<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP, GADTs, ViewPatterns #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-comment">-- | The @FamInst@ type: family instance heads</span><span>
</span><span id="line-4"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Tc.Instance.Family</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-5"></span><span>        </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier">FamInstEnvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcGetFamInstEnvs"><span class="hs-identifier">tcGetFamInstEnvs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-6"></span><span>        </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#checkFamInstConsistency"><span class="hs-identifier">checkFamInstConsistency</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcExtendLocalFamInstEnv"><span class="hs-identifier">tcExtendLocalFamInstEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-7"></span><span>        </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst"><span class="hs-identifier">tcLookupDataFamInst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst_maybe"><span class="hs-identifier">tcLookupDataFamInst_maybe</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-8"></span><span>        </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcInstNewTyCon_maybe"><span class="hs-identifier">tcInstNewTyCon_maybe</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcTopNormaliseNewTypeTF_maybe"><span class="hs-identifier">tcTopNormaliseNewTypeTF_maybe</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-9"></span><span>        </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#newFamInst"><span class="hs-identifier">newFamInst</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-10"></span><span>
</span><span id="line-11"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Injectivity</span></span><span>
</span><span id="line-12"></span><span>        </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportInjectivityErrors"><span class="hs-identifier">reportInjectivityErrors</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportConflictingInjectivityErrs"><span class="hs-identifier">reportConflictingInjectivityErrs</span></a></span><span>
</span><span id="line-13"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Types.html"><span class="hs-identifier">GHC.Driver.Types</span></a></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html"><span class="hs-identifier">GHC.Core.FamInstEnv</span></a></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html"><span class="hs-identifier">GHC.Core.InstEnv</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html#roughMatchTcs"><span class="hs-identifier">roughMatchTcs</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.html"><span class="hs-identifier">GHC.Core.Coercion</span></a></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html"><span class="hs-identifier">GHC.Tc.Types.Evidence</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Iface.Load.html"><span class="hs-identifier">GHC.Iface.Load</span></a></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Monad.html"><span class="hs-identifier">GHC.Tc.Utils.Monad</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Instantiate.html"><span class="hs-identifier">GHC.Tc.Utils.Instantiate</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Instantiate.html#freshenTyVarBndrs"><span class="hs-identifier">freshenTyVarBndrs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Instantiate.html#freshenCoVarBndrsX"><span class="hs-identifier">freshenCoVarBndrsX</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html"><span class="hs-identifier">GHC.Types.SrcLoc</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">SrcLoc</span></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html"><span class="hs-identifier">GHC.Core.TyCon</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html"><span class="hs-identifier">GHC.Core.Coercion.Axiom</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Unit.Module.html"><span class="hs-identifier">GHC.Unit.Module</span></a></span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html"><span class="hs-identifier">GHC.Types.Name.Reader</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html"><span class="hs-identifier">GHC.Core.DataCon</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html#dataConName"><span class="hs-identifier">dataConName</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html"><span class="hs-identifier">GHC.Data.Maybe</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html"><span class="hs-identifier">GHC.Core.TyCo.Rep</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.FVs.html"><span class="hs-identifier">GHC.Core.TyCo.FVs</span></a></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html"><span class="hs-identifier">GHC.Core.TyCo.Ppr</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html#pprWithExplicitKindsWhen"><span class="hs-identifier">pprWithExplicitKindsWhen</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Panic.html"><span class="hs-identifier">GHC.Utils.Panic</span></a></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.FV.html"><span class="hs-identifier">GHC.Utils.FV</span></a></span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html"><span class="hs-identifier">GHC.Data.Bag</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier">Bag</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#unionBags"><span class="hs-identifier">unionBags</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#unitBag"><span class="hs-identifier">unitBag</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.OldList.html#sortBy"><span class="hs-identifier">sortBy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.NonEmpty.html#"><span class="hs-identifier">Data.List.NonEmpty</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#NonEmpty"><span class="hs-identifier">NonEmpty</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Function.html#"><span class="hs-identifier">Data.Function</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Function.html#on"><span class="hs-identifier">on</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../ghc-boot/src/GHC.LanguageExtensions.html#"><span class="hs-identifier">GHC.LanguageExtensions</span></a></span><span>  </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">LangExt</span></span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-53"></span><span class="hs-comment">{- Note [The type family instance consistency story]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To preserve type safety we must ensure that for any given module, all
the type family instances used either in that module or in any module
it directly or indirectly imports are consistent. For example, consider

  module F where
    type family F a

  module A where
    import F( F )
    type instance F Int = Bool
    f :: F Int -&gt; Bool
    f x = x

  module B where
    import F( F )
    type instance F Int = Char
    g :: Char -&gt; F Int
    g x = x

  module Bad where
    import A( f )
    import B( g )
    bad :: Char -&gt; Int
    bad c = f (g c)

Even though module Bad never mentions the type family F at all, by
combining the functions f and g that were type checked in contradictory
type family instance environments, the function bad is able to coerce
from one type to another. So when we type check Bad we must verify that
the type family instances defined in module A are consistent with those
defined in module B.

How do we ensure that we maintain the necessary consistency?

* Call a module which defines at least one type family instance a
  &quot;family instance module&quot;. This flag `mi_finsts` is recorded in the
  interface file.

* For every module we calculate the set of all of its direct and
  indirect dependencies that are family instance modules. This list
  `dep_finsts` is also recorded in the interface file so we can compute
  this list for a module from the lists for its direct dependencies.

* When type checking a module M we check consistency of all the type
  family instances that are either provided by its `dep_finsts` or
  defined in the module M itself. This is a pairwise check, i.e., for
  every pair of instances we must check that they are consistent.

  - For family instances coming from `dep_finsts`, this is checked in
    checkFamInstConsistency, called from tcRnImports. See Note
    [Checking family instance consistency] for details on this check
    (and in particular how we avoid having to do all these checks for
    every module we compile).

  - That leaves checking the family instances defined in M itself
    against instances defined in either M or its `dep_finsts`. This is
    checked in `tcExtendLocalFamInstEnv'.

There are four subtle points in this scheme which have not been
addressed yet.

* We have checked consistency of the family instances *defined* by M
  or its imports, but this is not by definition the same thing as the
  family instances *used* by M or its imports.  Specifically, we need to
  ensure when we use a type family instance while compiling M that this
  instance was really defined from either M or one of its imports,
  rather than being an instance that we happened to know about from
  reading an interface file in the course of compiling an unrelated
  module. Otherwise, we'll end up with no record of the fact that M
  depends on this family instance and type safety will be compromised.
  See #13102.

* It can also happen that M uses a function defined in another module
  which is not transitively imported by M. Examples include the
  desugaring of various overloaded constructs, and references inserted
  by Template Haskell splices. If that function's definition makes use
  of type family instances which are not checked against those visible
  from M, type safety can again be compromised. See #13251.

* When a module C imports a boot module B.hs-boot, we check that C's
  type family instances are compatible with those visible from
  B.hs-boot. However, C will eventually be linked against a different
  module B.hs, which might define additional type family instances which
  are inconsistent with C's. This can also lead to loss of type safety.
  See #9562.

* The call to checkFamConsistency for imported functions occurs very
  early (in tcRnImports) and that causes problems if the imported
  instances use type declared in the module being compiled.
  See Note [Loading your own hi-boot file] in GHC.Iface.Load.
-}</span><span>
</span><span id="line-147"></span><span>
</span><span id="line-148"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                 Making a FamInst
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-155"></span><span>
</span><span id="line-156"></span><span class="hs-comment">-- All type variables in a FamInst must be fresh. This function</span><span>
</span><span id="line-157"></span><span class="hs-comment">-- creates the fresh variables and applies the necessary substitution</span><span>
</span><span id="line-158"></span><span class="hs-comment">-- It is defined here to avoid a dependency from FamInstEnv on the monad</span><span>
</span><span id="line-159"></span><span class="hs-comment">-- code.</span><span>
</span><span id="line-160"></span><span>
</span><span id="line-161"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#newFamInst"><span class="hs-identifier hs-type">newFamInst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamFlavor"><span class="hs-identifier hs-type">FamFlavor</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxiom"><span class="hs-identifier hs-type">CoAxiom</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Unbranched"><span class="hs-identifier hs-type">Unbranched</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span>
</span><span id="line-162"></span><span class="hs-comment">-- Freshen the type variables of the FamInst branches</span><span>
</span><span id="line-163"></span><span id="newFamInst"><span class="annot"><span class="annottext">newFamInst :: FamFlavor -&gt; CoAxiom Unbranched -&gt; TcM FamInst
</span><a href="GHC.Tc.Instance.Family.html#newFamInst"><span class="hs-identifier hs-var hs-var">newFamInst</span></a></span></span><span> </span><span id="local-6989586621681105477"><span class="annot"><span class="annottext">FamFlavor
</span><a href="#local-6989586621681105477"><span class="hs-identifier hs-var">flavor</span></a></span></span><span> </span><span id="local-6989586621681105476"><span class="annot"><span class="annottext">axiom :: CoAxiom Unbranched
</span><a href="#local-6989586621681105476"><span class="hs-identifier hs-var">axiom</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxiom"><span class="hs-identifier hs-type">CoAxiom</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">co_ax_tc :: forall (br :: BranchFlag). CoAxiom br -&gt; TyCon
</span><a href="GHC.Core.Coercion.Axiom.html#co_ax_tc"><span class="hs-identifier hs-var">co_ax_tc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105473"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105473"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-164"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-165"></span><span>         </span><span class="hs-comment">-- Freshen the type variables</span><span>
</span><span id="line-166"></span><span>         </span><span class="hs-special">(</span><span id="local-6989586621681105472"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681105472"><span class="hs-identifier hs-var">subst</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105471"><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105471"><span class="hs-identifier hs-var">tvs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TyCoVar] -&gt; TcM (TCvSubst, [TyCoVar])
</span><a href="GHC.Tc.Utils.Instantiate.html#freshenTyVarBndrs"><span class="hs-identifier hs-var">freshenTyVarBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105470"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-167"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105469"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681105469"><span class="hs-identifier hs-var">subst</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105468"><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105468"><span class="hs-identifier hs-var">cvs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TCvSubst -&gt; [TyCoVar] -&gt; TcM (TCvSubst, [TyCoVar])
</span><a href="GHC.Tc.Utils.Instantiate.html#freshenCoVarBndrsX"><span class="hs-identifier hs-var">freshenCoVarBndrsX</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681105472"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105467"><span class="hs-identifier hs-var">cvs</span></a></span><span>
</span><span id="line-168"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105466"><span class="annot"><span class="annottext">lhs' :: [Type]
</span><a href="#local-6989586621681105466"><span class="hs-identifier hs-var hs-var">lhs'</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [Type] -&gt; [Type]
TCvSubst -&gt; [Type] -&gt; [Type]
</span><a href="GHC.Core.TyCo.Subst.html#substTys"><span class="hs-identifier hs-var">substTys</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681105469"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105464"><span class="hs-identifier hs-var">lhs</span></a></span><span>
</span><span id="line-169"></span><span>             </span><span id="local-6989586621681105463"><span class="annot"><span class="annottext">rhs' :: Type
</span><a href="#local-6989586621681105463"><span class="hs-identifier hs-var hs-var">rhs'</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; Type -&gt; Type
TCvSubst -&gt; Type -&gt; Type
</span><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier hs-var">substTy</span></a></span><span>  </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681105469"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105461"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; TcM FamInst
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInst :: CoAxiom Unbranched
-&gt; FamFlavor
-&gt; Name
-&gt; [Maybe Name]
-&gt; [TyCoVar]
-&gt; [TyCoVar]
-&gt; [Type]
-&gt; Type
-&gt; FamInst
</span><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fi_fam :: Name
</span><a href="GHC.Core.FamInstEnv.html#fi_fam"><span class="hs-identifier hs-var">fi_fam</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Name
</span><a href="GHC.Core.TyCon.html#tyConName"><span class="hs-identifier hs-var hs-var">tyConName</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105473"><span class="hs-identifier hs-var">fam_tc</span></a></span><span>
</span><span id="line-172"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_flavor :: FamFlavor
</span><a href="GHC.Core.FamInstEnv.html#fi_flavor"><span class="hs-identifier hs-var">fi_flavor</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamFlavor
</span><a href="#local-6989586621681105477"><span class="hs-identifier hs-var">flavor</span></a></span><span>
</span><span id="line-173"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_tcs :: [Maybe Name]
</span><a href="GHC.Core.FamInstEnv.html#fi_tcs"><span class="hs-identifier hs-var">fi_tcs</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Maybe Name]
</span><a href="GHC.Core.Unify.html#roughMatchTcs"><span class="hs-identifier hs-var">roughMatchTcs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105464"><span class="hs-identifier hs-var">lhs</span></a></span><span>
</span><span id="line-174"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_tvs :: [TyCoVar]
</span><a href="GHC.Core.FamInstEnv.html#fi_tvs"><span class="hs-identifier hs-var">fi_tvs</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105471"><span class="hs-identifier hs-var">tvs'</span></a></span><span>
</span><span id="line-175"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_cvs :: [TyCoVar]
</span><a href="GHC.Core.FamInstEnv.html#fi_cvs"><span class="hs-identifier hs-var">fi_cvs</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105468"><span class="hs-identifier hs-var">cvs'</span></a></span><span>
</span><span id="line-176"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_tys :: [Type]
</span><a href="GHC.Core.FamInstEnv.html#fi_tys"><span class="hs-identifier hs-var">fi_tys</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105466"><span class="hs-identifier hs-var">lhs'</span></a></span><span>
</span><span id="line-177"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_rhs :: Type
</span><a href="GHC.Core.FamInstEnv.html#fi_rhs"><span class="hs-identifier hs-var">fi_rhs</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105463"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-178"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_axiom :: CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#fi_axiom"><span class="hs-identifier hs-var">fi_axiom</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105476"><span class="hs-identifier hs-var">axiom</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-179"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-180"></span><span>    </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cab_tvs :: CoAxBranch -&gt; [TyCoVar]
</span><a href="GHC.Core.Coercion.Axiom.html#cab_tvs"><span class="hs-identifier hs-var">cab_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105470"><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105470"><span class="hs-identifier hs-var">tvs</span></a></span></span><span>
</span><span id="line-181"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cab_cvs :: CoAxBranch -&gt; [TyCoVar]
</span><a href="GHC.Core.Coercion.Axiom.html#cab_cvs"><span class="hs-identifier hs-var">cab_cvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105467"><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105467"><span class="hs-identifier hs-var">cvs</span></a></span></span><span>
</span><span id="line-182"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cab_lhs :: CoAxBranch -&gt; [Type]
</span><a href="GHC.Core.Coercion.Axiom.html#cab_lhs"><span class="hs-identifier hs-var">cab_lhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105464"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105464"><span class="hs-identifier hs-var">lhs</span></a></span></span><span>
</span><span id="line-183"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cab_rhs :: CoAxBranch -&gt; Type
</span><a href="GHC.Core.Coercion.Axiom.html#cab_rhs"><span class="hs-identifier hs-var">cab_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105461"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105461"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; CoAxBranch
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomSingleBranch"><span class="hs-identifier hs-var">coAxiomSingleBranch</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105476"><span class="hs-identifier hs-var">axiom</span></a></span><span>
</span><span id="line-184"></span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
        Optimised overlap checking for family instances
*                                                                      *
************************************************************************

Note [Checking family instance consistency]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For any two family instance modules that we import directly or indirectly, we
check whether the instances in the two modules are consistent, *unless* we can
be certain that the instances of the two modules have already been checked for
consistency during the compilation of modules that we import.

Why do we need to check?  Consider
   module X1 where                module X2 where
    data T1                         data T2
    type instance F T1 b = Int      type instance F a T2 = Char
    f1 :: F T1 a -&gt; Int             f2 :: Char -&gt; F a T2
    f1 x = x                        f2 x = x

Now if we import both X1 and X2 we could make (f2 . f1) :: Int -&gt; Char.
Notice that neither instance is an orphan.

How do we know which pairs of modules have already been checked? For each
module M we directly import, we look up the family instance modules that M
imports (directly or indirectly), say F1, ..., FN. For any two modules
among M, F1, ..., FN, we know that the family instances defined in those
two modules are consistent--because we checked that when we compiled M.

For every other pair of family instance modules we import (directly or
indirectly), we check that they are consistent now. (So that we can be
certain that the modules in our `GHC.Driver.Types.dep_finsts' are consistent.)

There is some fancy footwork regarding hs-boot module loops, see
Note [Don't check hs-boot type family instances too early]

Note [Checking family instance optimization]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As explained in Note [Checking family instance consistency]
we need to ensure that every pair of transitive imports that define type family
instances is consistent.

Let's define df(A) = transitive imports of A that define type family instances
+ A, if A defines type family instances

Then for every direct import A, df(A) is already consistent.

Let's name the current module M.

We want to make sure that df(M) is consistent.
df(M) = df(D_1) U df(D_2) U ... U df(D_i) where D_1 .. D_i are direct imports.

We perform the check iteratively, maintaining a set of consistent modules 'C'
and trying to add df(D_i) to it.

The key part is how to ensure that the union C U df(D_i) is consistent.

Let's consider two modules: A and B from C U df(D_i).
There are nine possible ways to choose A and B from C U df(D_i):

             | A in C only      | A in C and B in df(D_i) | A in df(D_i) only
--------------------------------------------------------------------------------
B in C only  | Already checked  | Already checked         | Needs to be checked
             | when checking C  | when checking C         |
--------------------------------------------------------------------------------
B in C and   | Already checked  | Already checked         | Already checked when
B in df(D_i) | when checking C  | when checking C         | checking df(D_i)
--------------------------------------------------------------------------------
B in df(D_i) | Needs to be      | Already checked         | Already checked when
only         | checked          | when checking df(D_i)   | checking df(D_i)

That means to ensure that C U df(D_i) is consistent we need to check every
module from C - df(D_i) against every module from df(D_i) - C and
every module from df(D_i) - C against every module from C - df(D_i).
But since the checks are symmetric it suffices to pick A from C - df(D_i)
and B from df(D_i) - C.

In other words these are the modules we need to check:
  [ (m1, m2) | m1 &lt;- C, m1 not in df(D_i)
             , m2 &lt;- df(D_i), m2 not in C ]

One final thing to note here is that if there's lot of overlap between
subsequent df(D_i)'s then we expect those set differences to be small.
That situation should be pretty common in practice, there's usually
a set of utility modules that every module imports directly or indirectly.

This is basically the idea from #13092, comment:14.
-}</span><span>
</span><span id="line-275"></span><span>
</span><span id="line-276"></span><span class="hs-comment">-- This function doesn't check ALL instances for consistency,</span><span>
</span><span id="line-277"></span><span class="hs-comment">-- only ones that aren't involved in recursive knot-tying</span><span>
</span><span id="line-278"></span><span class="hs-comment">-- loops; see Note [Don't check hs-boot type family instances too early].</span><span>
</span><span id="line-279"></span><span class="hs-comment">-- We don't need to check the current module, this is done in</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- tcExtendLocalFamInstEnv.</span><span>
</span><span id="line-281"></span><span class="hs-comment">-- See Note [The type family instance consistency story].</span><span>
</span><span id="line-282"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#checkFamInstConsistency"><span class="hs-identifier hs-type">checkFamInstConsistency</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-283"></span><span id="checkFamInstConsistency"><span class="annot"><span class="annottext">checkFamInstConsistency :: [Module] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkFamInstConsistency"><span class="hs-identifier hs-var hs-var">checkFamInstConsistency</span></a></span></span><span> </span><span id="local-6989586621681105444"><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105444"><span class="hs-identifier hs-var">directlyImpMods</span></a></span></span><span>
</span><span id="line-284"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105443"><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105443"><span class="hs-identifier hs-var">eps</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105442"><span class="annot"><span class="annottext">HomePackageTable
</span><a href="#local-6989586621681105442"><span class="hs-identifier hs-var">hpt</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv (ExternalPackageState, HomePackageTable)
forall gbl lcl.
TcRnIf gbl lcl (ExternalPackageState, HomePackageTable)
</span><a href="GHC.Tc.Utils.Monad.html#getEpsAndHpt"><span class="hs-identifier hs-var">getEpsAndHpt</span></a></span><span>
</span><span id="line-285"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;checkFamInstConsistency&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Module] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105444"><span class="hs-identifier hs-var">directlyImpMods</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-286"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-comment">-- Fetch the iface of a given module.  Must succeed as</span><span>
</span><span id="line-287"></span><span>               </span><span class="hs-comment">-- all directly imported modules must already have been loaded.</span><span>
</span><span id="line-288"></span><span>               </span><span id="local-6989586621681105438"><span class="annot"><span class="annottext">modIface :: Module -&gt; ModIface
</span><a href="#local-6989586621681105438"><span class="hs-identifier hs-var hs-var">modIface</span></a></span></span><span> </span><span id="local-6989586621681105437"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105437"><span class="hs-identifier hs-var">mod</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-289"></span><span>                 </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">HomePackageTable -&gt; PackageIfaceTable -&gt; Module -&gt; Maybe ModIface
</span><a href="GHC.Driver.Types.html#lookupIfaceByModule"><span class="hs-identifier hs-var">lookupIfaceByModule</span></a></span><span> </span><span class="annot"><span class="annottext">HomePackageTable
</span><a href="#local-6989586621681105442"><span class="hs-identifier hs-var">hpt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ExternalPackageState -&gt; PackageIfaceTable
</span><a href="GHC.Driver.Types.html#eps_PIT"><span class="hs-identifier hs-var hs-var">eps_PIT</span></a></span><span> </span><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105443"><span class="hs-identifier hs-var">eps</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105437"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-290"></span><span>                   </span><span class="annot"><span class="annottext">Maybe ModIface
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; ModIface
forall a. String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Panic.html#panicDoc"><span class="hs-identifier hs-var">panicDoc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;FamInst.checkFamInstConsistency&quot;</span></span><span>
</span><span id="line-291"></span><span>                                          </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105437"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">HomePackageTable -&gt; SDoc
</span><a href="GHC.Driver.Types.html#pprHPT"><span class="hs-identifier hs-var">pprHPT</span></a></span><span> </span><span class="annot"><span class="annottext">HomePackageTable
</span><a href="#local-6989586621681105442"><span class="hs-identifier hs-var">hpt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-292"></span><span>                   </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681105431"><span class="annot"><span class="annottext">ModIface
</span><a href="#local-6989586621681105431"><span class="hs-identifier hs-var">iface</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ModIface
</span><a href="#local-6989586621681105431"><span class="hs-identifier hs-var">iface</span></a></span><span>
</span><span id="line-293"></span><span>
</span><span id="line-294"></span><span>               </span><span class="hs-comment">-- Which family instance modules were checked for consistency</span><span>
</span><span id="line-295"></span><span>               </span><span class="hs-comment">-- when we compiled `mod`?</span><span>
</span><span id="line-296"></span><span>               </span><span class="hs-comment">-- Itself (if a family instance module) and its dep_finsts.</span><span>
</span><span id="line-297"></span><span>               </span><span class="hs-comment">-- This is df(D_i) from</span><span>
</span><span id="line-298"></span><span>               </span><span class="hs-comment">-- Note [Checking family instance optimization]</span><span>
</span><span id="line-299"></span><span>             </span><span class="hs-special">;</span><span> </span><span class="annot"><a href="#local-6989586621681105430"><span class="hs-identifier hs-type">modConsistent</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-300"></span><span>             </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105430"><span class="annot"><span class="annottext">modConsistent :: Module -&gt; [Module]
</span><a href="#local-6989586621681105430"><span class="hs-identifier hs-var hs-var">modConsistent</span></a></span></span><span> </span><span id="local-6989586621681105429"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105429"><span class="hs-identifier hs-var">mod</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-301"></span><span>                 </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">ModIfaceBackend -&gt; WhetherHasFamInst
</span><a href="GHC.Driver.Types.html#mi_finsts"><span class="hs-identifier hs-var hs-var">mi_finsts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ModIface -&gt; IfaceBackendExts 'ModIfaceFinal
forall (phase :: ModIfacePhase).
ModIface_ phase -&gt; IfaceBackendExts phase
</span><a href="GHC.Driver.Types.html#mi_final_exts"><span class="hs-identifier hs-var hs-var">mi_final_exts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; ModIface
</span><a href="#local-6989586621681105438"><span class="hs-identifier hs-var">modIface</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105429"><span class="hs-identifier hs-var">mod</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105429"><span class="hs-identifier hs-var">mod</span></a></span><span class="annot"><span class="annottext">Module -&gt; [Module] -&gt; [Module]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105426"><span class="hs-identifier hs-var">deps</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105426"><span class="hs-identifier hs-var">deps</span></a></span><span>
</span><span id="line-302"></span><span>                 </span><span class="hs-keyword">where</span><span>
</span><span id="line-303"></span><span>                 </span><span id="local-6989586621681105426"><span class="annot"><span class="annottext">deps :: [Module]
</span><a href="#local-6989586621681105426"><span class="hs-identifier hs-var hs-var">deps</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Dependencies -&gt; [Module]
</span><a href="GHC.Driver.Types.html#dep_finsts"><span class="hs-identifier hs-var hs-var">dep_finsts</span></a></span><span> </span><span class="annot"><span class="annottext">(Dependencies -&gt; [Module])
-&gt; (Module -&gt; Dependencies) -&gt; Module -&gt; [Module]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">ModIface -&gt; Dependencies
forall (phase :: ModIfacePhase). ModIface_ phase -&gt; Dependencies
</span><a href="GHC.Driver.Types.html#mi_deps"><span class="hs-identifier hs-var hs-var">mi_deps</span></a></span><span> </span><span class="annot"><span class="annottext">(ModIface -&gt; Dependencies)
-&gt; (Module -&gt; ModIface) -&gt; Module -&gt; Dependencies
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; ModIface
</span><a href="#local-6989586621681105438"><span class="hs-identifier hs-var">modIface</span></a></span><span> </span><span class="annot"><span class="annottext">(Module -&gt; [Module]) -&gt; Module -&gt; [Module]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105429"><span class="hs-identifier hs-var">mod</span></a></span><span>
</span><span id="line-304"></span><span>
</span><span id="line-305"></span><span>             </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105422"><span class="annot"><span class="annottext">hmiModule :: HomeModInfo -&gt; Module
</span><a href="#local-6989586621681105422"><span class="hs-identifier hs-var hs-var">hmiModule</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ModIface -&gt; Module
forall (phase :: ModIfacePhase). ModIface_ phase -&gt; Module
</span><a href="GHC.Driver.Types.html#mi_module"><span class="hs-identifier hs-var hs-var">mi_module</span></a></span><span> </span><span class="annot"><span class="annottext">(ModIface -&gt; Module)
-&gt; (HomeModInfo -&gt; ModIface) -&gt; HomeModInfo -&gt; Module
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">HomeModInfo -&gt; ModIface
</span><a href="GHC.Driver.Types.html#hm_iface"><span class="hs-identifier hs-var hs-var">hm_iface</span></a></span><span>
</span><span id="line-306"></span><span>             </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105419"><span class="annot"><span class="annottext">hmiFamInstEnv :: HomeModInfo -&gt; FamInstEnv
</span><a href="#local-6989586621681105419"><span class="hs-identifier hs-var hs-var">hmiFamInstEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; [FamInst] -&gt; FamInstEnv
</span><a href="GHC.Core.FamInstEnv.html#extendFamInstEnvList"><span class="hs-identifier hs-var">extendFamInstEnvList</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="GHC.Core.FamInstEnv.html#emptyFamInstEnv"><span class="hs-identifier hs-var">emptyFamInstEnv</span></a></span><span>
</span><span id="line-307"></span><span>                               </span><span class="annot"><span class="annottext">([FamInst] -&gt; FamInstEnv)
-&gt; (HomeModInfo -&gt; [FamInst]) -&gt; HomeModInfo -&gt; FamInstEnv
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">ModDetails -&gt; [FamInst]
</span><a href="GHC.Driver.Types.html#md_fam_insts"><span class="hs-identifier hs-var hs-var">md_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">(ModDetails -&gt; [FamInst])
-&gt; (HomeModInfo -&gt; ModDetails) -&gt; HomeModInfo -&gt; [FamInst]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">HomeModInfo -&gt; ModDetails
</span><a href="GHC.Driver.Types.html#hm_details"><span class="hs-identifier hs-var hs-var">hm_details</span></a></span><span>
</span><span id="line-308"></span><span>             </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105414"><span class="annot"><span class="annottext">hpt_fam_insts :: ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105414"><span class="hs-identifier hs-var hs-var">hpt_fam_insts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(Module, FamInstEnv)] -&gt; ModuleEnv FamInstEnv
forall a. [(Module, a)] -&gt; ModuleEnv a
</span><a href="GHC.Unit.Module.Env.html#mkModuleEnv"><span class="hs-identifier hs-var">mkModuleEnv</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HomeModInfo -&gt; Module
</span><a href="#local-6989586621681105422"><span class="hs-identifier hs-var">hmiModule</span></a></span><span> </span><span class="annot"><span class="annottext">HomeModInfo
</span><a href="#local-6989586621681105412"><span class="hs-identifier hs-var">hmi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">HomeModInfo -&gt; FamInstEnv
</span><a href="#local-6989586621681105419"><span class="hs-identifier hs-var">hmiFamInstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">HomeModInfo
</span><a href="#local-6989586621681105412"><span class="hs-identifier hs-var">hmi</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-309"></span><span>                                           </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621681105412"><span class="annot"><span class="annottext">HomeModInfo
</span><a href="#local-6989586621681105412"><span class="hs-identifier hs-var">hmi</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">HomePackageTable -&gt; [HomeModInfo]
</span><a href="GHC.Driver.Types.html#eltsHpt"><span class="hs-identifier hs-var">eltsHpt</span></a></span><span> </span><span class="annot"><span class="annottext">HomePackageTable
</span><a href="#local-6989586621681105442"><span class="hs-identifier hs-var">hpt</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-310"></span><span>
</span><span id="line-311"></span><span>             </span><span class="hs-special">}</span><span>
</span><span id="line-312"></span><span>
</span><span id="line-313"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv -&gt; (Module -&gt; [Module]) -&gt; [Module] -&gt; TcM ()
</span><a href="#local-6989586621681105410"><span class="hs-identifier hs-var">checkMany</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105414"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; [Module]
</span><a href="#local-6989586621681105430"><span class="hs-identifier hs-var">modConsistent</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105444"><span class="hs-identifier hs-var">directlyImpMods</span></a></span><span>
</span><span id="line-314"></span><span>       </span><span class="hs-special">}</span><span>
</span><span id="line-315"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-316"></span><span>    </span><span class="hs-comment">-- See Note [Checking family instance optimization]</span><span>
</span><span id="line-317"></span><span>    </span><span class="annot"><a href="#local-6989586621681105410"><span class="hs-identifier hs-type">checkMany</span></a></span><span>
</span><span id="line-318"></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Unit.Module.Env.html#ModuleEnv"><span class="hs-identifier hs-type">ModuleEnv</span></a></span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnv"><span class="hs-identifier hs-type">FamInstEnv</span></a></span><span>   </span><span class="hs-comment">-- home package family instances</span><span>
</span><span id="line-319"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>   </span><span class="hs-comment">-- given A, modules checked when A was checked</span><span>
</span><span id="line-320"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span class="hs-special">]</span><span>               </span><span class="hs-comment">-- modules to process</span><span>
</span><span id="line-321"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-322"></span><span>    </span><span id="local-6989586621681105410"><span class="annot"><span class="annottext">checkMany :: ModuleEnv FamInstEnv -&gt; (Module -&gt; [Module]) -&gt; [Module] -&gt; TcM ()
</span><a href="#local-6989586621681105410"><span class="hs-identifier hs-var hs-var">checkMany</span></a></span></span><span> </span><span id="local-6989586621681105409"><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105409"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span></span><span> </span><span id="local-6989586621681105408"><span class="annot"><span class="annottext">Module -&gt; [Module]
</span><a href="#local-6989586621681105408"><span class="hs-identifier hs-var">modConsistent</span></a></span></span><span> </span><span id="local-6989586621681105407"><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105407"><span class="hs-identifier hs-var">mods</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Module] -&gt; ModuleSet -&gt; [Module] -&gt; TcM ()
</span><a href="#local-6989586621681105406"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="GHC.Unit.Module.Env.html#emptyModuleSet"><span class="hs-identifier hs-var">emptyModuleSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105407"><span class="hs-identifier hs-var">mods</span></a></span><span>
</span><span id="line-323"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-324"></span><span>      </span><span class="annot"><a href="#local-6989586621681105406"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- list of consistent modules</span><span>
</span><span id="line-325"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Unit.Module.Env.html#ModuleSet"><span class="hs-identifier hs-type">ModuleSet</span></a></span><span> </span><span class="hs-comment">-- set of consistent modules, same elements as the</span><span>
</span><span id="line-326"></span><span>                      </span><span class="hs-comment">-- list above</span><span>
</span><span id="line-327"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- modules to process</span><span>
</span><span id="line-328"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-329"></span><span>      </span><span id="local-6989586621681105406"><span class="annot"><span class="annottext">go :: [Module] -&gt; ModuleSet -&gt; [Module] -&gt; TcM ()
</span><a href="#local-6989586621681105406"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-330"></span><span>      </span><span class="annot"><a href="#local-6989586621681105406"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621681105404"><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105404"><span class="hs-identifier hs-var">consistent</span></a></span></span><span> </span><span id="local-6989586621681105403"><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621681105403"><span class="hs-identifier hs-var">consistent_set</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105402"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105402"><span class="hs-identifier hs-var">mod</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621681105401"><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105401"><span class="hs-identifier hs-var">mods</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-331"></span><span>        </span><span class="annot"><span class="annottext">[TcM ()] -&gt; TcM ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a.
(Foldable t, Monad m) =&gt;
t (m a) -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#sequence_"><span class="hs-identifier hs-var">sequence_</span></a></span><span>
</span><span id="line-332"></span><span>          </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv -&gt; Module -&gt; Module -&gt; TcM ()
</span><a href="#local-6989586621681105399"><span class="hs-identifier hs-var">check</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105409"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105398"><span class="hs-identifier hs-var">m1</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105397"><span class="hs-identifier hs-var">m2</span></a></span><span>
</span><span id="line-333"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621681105398"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105398"><span class="hs-identifier hs-var">m1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105396"><span class="hs-identifier hs-var">to_check_from_mod</span></a></span><span>
</span><span id="line-334"></span><span>            </span><span class="hs-comment">-- loop over toCheckFromMod first, it's usually smaller,</span><span>
</span><span id="line-335"></span><span>            </span><span class="hs-comment">-- it may even be empty</span><span>
</span><span id="line-336"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105397"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105397"><span class="hs-identifier hs-var">m2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105395"><span class="hs-identifier hs-var">to_check_from_consistent</span></a></span><span>
</span><span id="line-337"></span><span>          </span><span class="hs-special">]</span><span>
</span><span id="line-338"></span><span>        </span><span class="annot"><span class="annottext">[Module] -&gt; ModuleSet -&gt; [Module] -&gt; TcM ()
</span><a href="#local-6989586621681105406"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105394"><span class="hs-identifier hs-var">consistent'</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621681105393"><span class="hs-identifier hs-var">consistent_set'</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105401"><span class="hs-identifier hs-var">mods</span></a></span><span>
</span><span id="line-339"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-340"></span><span>        </span><span id="local-6989586621681105392"><span class="annot"><span class="annottext">mod_deps_consistent :: [Module]
</span><a href="#local-6989586621681105392"><span class="hs-identifier hs-var hs-var">mod_deps_consistent</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Module -&gt; [Module]
</span><a href="#local-6989586621681105408"><span class="hs-identifier hs-var">modConsistent</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105402"><span class="hs-identifier hs-var">mod</span></a></span><span>
</span><span id="line-341"></span><span>        </span><span id="local-6989586621681105391"><span class="annot"><span class="annottext">mod_deps_consistent_set :: ModuleSet
</span><a href="#local-6989586621681105391"><span class="hs-identifier hs-var hs-var">mod_deps_consistent_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Module] -&gt; ModuleSet
</span><a href="GHC.Unit.Module.Env.html#mkModuleSet"><span class="hs-identifier hs-var">mkModuleSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105392"><span class="hs-identifier hs-var">mod_deps_consistent</span></a></span><span>
</span><span id="line-342"></span><span>        </span><span id="local-6989586621681105394"><span class="annot"><span class="annottext">consistent' :: [Module]
</span><a href="#local-6989586621681105394"><span class="hs-identifier hs-var hs-var">consistent'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105396"><span class="hs-identifier hs-var">to_check_from_mod</span></a></span><span> </span><span class="annot"><span class="annottext">[Module] -&gt; [Module] -&gt; [Module]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105404"><span class="hs-identifier hs-var">consistent</span></a></span><span>
</span><span id="line-343"></span><span>        </span><span id="local-6989586621681105393"><span class="annot"><span class="annottext">consistent_set' :: ModuleSet
</span><a href="#local-6989586621681105393"><span class="hs-identifier hs-var hs-var">consistent_set'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-344"></span><span>          </span><span class="annot"><span class="annottext">ModuleSet -&gt; [Module] -&gt; ModuleSet
</span><a href="GHC.Unit.Module.Env.html#extendModuleSetList"><span class="hs-identifier hs-var">extendModuleSetList</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621681105403"><span class="hs-identifier hs-var">consistent_set</span></a></span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105396"><span class="hs-identifier hs-var">to_check_from_mod</span></a></span><span>
</span><span id="line-345"></span><span>        </span><span id="local-6989586621681105395"><span class="annot"><span class="annottext">to_check_from_consistent :: [Module]
</span><a href="#local-6989586621681105395"><span class="hs-identifier hs-var hs-var">to_check_from_consistent</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-346"></span><span>          </span><span class="annot"><span class="annottext">(Module -&gt; WhetherHasFamInst) -&gt; [Module] -&gt; [Module]
forall a. (a -&gt; WhetherHasFamInst) -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#filterOut"><span class="hs-identifier hs-var">filterOut</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; ModuleSet -&gt; WhetherHasFamInst
</span><a href="GHC.Unit.Module.Env.html#elemModuleSet"><span class="hs-operator hs-var">`elemModuleSet`</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621681105391"><span class="hs-identifier hs-var">mod_deps_consistent_set</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105404"><span class="hs-identifier hs-var">consistent</span></a></span><span>
</span><span id="line-347"></span><span>        </span><span id="local-6989586621681105396"><span class="annot"><span class="annottext">to_check_from_mod :: [Module]
</span><a href="#local-6989586621681105396"><span class="hs-identifier hs-var hs-var">to_check_from_mod</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-348"></span><span>          </span><span class="annot"><span class="annottext">(Module -&gt; WhetherHasFamInst) -&gt; [Module] -&gt; [Module]
forall a. (a -&gt; WhetherHasFamInst) -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#filterOut"><span class="hs-identifier hs-var">filterOut</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; ModuleSet -&gt; WhetherHasFamInst
</span><a href="GHC.Unit.Module.Env.html#elemModuleSet"><span class="hs-operator hs-var">`elemModuleSet`</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleSet
</span><a href="#local-6989586621681105403"><span class="hs-identifier hs-var">consistent_set</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Module]
</span><a href="#local-6989586621681105392"><span class="hs-identifier hs-var">mod_deps_consistent</span></a></span><span>
</span><span id="line-349"></span><span>        </span><span class="hs-comment">-- Why don't we just minusModuleSet here?</span><span>
</span><span id="line-350"></span><span>        </span><span class="hs-comment">-- We could, but doing so means one of two things:</span><span>
</span><span id="line-351"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-352"></span><span>        </span><span class="hs-comment">--   1. When looping over the cartesian product we convert</span><span>
</span><span id="line-353"></span><span>        </span><span class="hs-comment">--   a set into a non-deterministicly ordered list. Which</span><span>
</span><span id="line-354"></span><span>        </span><span class="hs-comment">--   happens to be fine for interface file determinism</span><span>
</span><span id="line-355"></span><span>        </span><span class="hs-comment">--   in this case, today, because the order only</span><span>
</span><span id="line-356"></span><span>        </span><span class="hs-comment">--   determines the order of deferred checks. But such</span><span>
</span><span id="line-357"></span><span>        </span><span class="hs-comment">--   invariants are hard to keep.</span><span>
</span><span id="line-358"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-359"></span><span>        </span><span class="hs-comment">--   2. When looping over the cartesian product we convert</span><span>
</span><span id="line-360"></span><span>        </span><span class="hs-comment">--   a set into a deterministically ordered list - this</span><span>
</span><span id="line-361"></span><span>        </span><span class="hs-comment">--   adds some additional cost of sorting for every</span><span>
</span><span id="line-362"></span><span>        </span><span class="hs-comment">--   direct import.</span><span>
</span><span id="line-363"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-364"></span><span>        </span><span class="hs-comment">--   That also explains why we need to keep both 'consistent'</span><span>
</span><span id="line-365"></span><span>        </span><span class="hs-comment">--   and 'consistentSet'.</span><span>
</span><span id="line-366"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-367"></span><span>        </span><span class="hs-comment">--   See also Note [ModuleEnv performance and determinism].</span><span>
</span><span id="line-368"></span><span>    </span><span id="local-6989586621681105399"><span class="annot"><span class="annottext">check :: ModuleEnv FamInstEnv -&gt; Module -&gt; Module -&gt; TcM ()
</span><a href="#local-6989586621681105399"><span class="hs-identifier hs-var hs-var">check</span></a></span></span><span> </span><span id="local-6989586621681105377"><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105377"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span></span><span> </span><span id="local-6989586621681105376"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105376"><span class="hs-identifier hs-var">m1</span></a></span></span><span> </span><span id="local-6989586621681105375"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105375"><span class="hs-identifier hs-var">m2</span></a></span></span><span>
</span><span id="line-369"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681105374"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105374"><span class="hs-identifier hs-var">env1'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv -&gt; Module -&gt; TcM FamInstEnv
</span><a href="GHC.Tc.Instance.Family.html#getFamInsts"><span class="hs-identifier hs-var">getFamInsts</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105377"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105376"><span class="hs-identifier hs-var">m1</span></a></span><span>
</span><span id="line-370"></span><span>           </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105372"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105372"><span class="hs-identifier hs-var">env2'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv -&gt; Module -&gt; TcM FamInstEnv
</span><a href="GHC.Tc.Instance.Family.html#getFamInsts"><span class="hs-identifier hs-var">getFamInsts</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105377"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105375"><span class="hs-identifier hs-var">m2</span></a></span><span>
</span><span id="line-371"></span><span>           </span><span class="hs-comment">-- We're checking each element of env1 against env2.</span><span>
</span><span id="line-372"></span><span>           </span><span class="hs-comment">-- The cost of that is dominated by the size of env1, because</span><span>
</span><span id="line-373"></span><span>           </span><span class="hs-comment">-- for each instance in env1 we look it up in the type family</span><span>
</span><span id="line-374"></span><span>           </span><span class="hs-comment">-- environment env2, and lookup is cheap.</span><span>
</span><span id="line-375"></span><span>           </span><span class="hs-comment">-- The code below ensures that env1 is the smaller environment.</span><span>
</span><span id="line-376"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105371"><span class="annot"><span class="annottext">sizeE1 :: Int
</span><a href="#local-6989586621681105371"><span class="hs-identifier hs-var hs-var">sizeE1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; Int
</span><a href="GHC.Core.FamInstEnv.html#famInstEnvSize"><span class="hs-identifier hs-var">famInstEnvSize</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105374"><span class="hs-identifier hs-var">env1'</span></a></span><span>
</span><span id="line-377"></span><span>                 </span><span id="local-6989586621681105369"><span class="annot"><span class="annottext">sizeE2 :: Int
</span><a href="#local-6989586621681105369"><span class="hs-identifier hs-var hs-var">sizeE2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; Int
</span><a href="GHC.Core.FamInstEnv.html#famInstEnvSize"><span class="hs-identifier hs-var">famInstEnvSize</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105372"><span class="hs-identifier hs-var">env2'</span></a></span><span>
</span><span id="line-378"></span><span>                 </span><span class="hs-special">(</span><span id="local-6989586621681105368"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105368"><span class="hs-identifier hs-var">env1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105367"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105367"><span class="hs-identifier hs-var">env2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621681105371"><span class="hs-identifier hs-var">sizeE1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; WhetherHasFamInst
forall a. Ord a =&gt; a -&gt; a -&gt; WhetherHasFamInst
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621681105369"><span class="hs-identifier hs-var">sizeE2</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105374"><span class="hs-identifier hs-var">env1'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105372"><span class="hs-identifier hs-var">env2'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-379"></span><span>                                                   </span><span class="hs-keyword">else</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105372"><span class="hs-identifier hs-var">env2'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105374"><span class="hs-identifier hs-var">env1'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-380"></span><span>           </span><span class="hs-comment">-- Note [Don't check hs-boot type family instances too early]</span><span>
</span><span id="line-381"></span><span>           </span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-382"></span><span>           </span><span class="hs-comment">-- Family instance consistency checking involves checking that</span><span>
</span><span id="line-383"></span><span>           </span><span class="hs-comment">-- the family instances of our imported modules are consistent with</span><span>
</span><span id="line-384"></span><span>           </span><span class="hs-comment">-- one another; this might lead you to think that this process</span><span>
</span><span id="line-385"></span><span>           </span><span class="hs-comment">-- has nothing to do with the module we are about to typecheck.</span><span>
</span><span id="line-386"></span><span>           </span><span class="hs-comment">-- Not so!  Consider the following case:</span><span>
</span><span id="line-387"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-388"></span><span>           </span><span class="hs-comment">--   -- A.hs-boot</span><span>
</span><span id="line-389"></span><span>           </span><span class="hs-comment">--   type family F a</span><span>
</span><span id="line-390"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-391"></span><span>           </span><span class="hs-comment">--   -- B.hs</span><span>
</span><span id="line-392"></span><span>           </span><span class="hs-comment">--   import {-# SOURCE #-} A</span><span>
</span><span id="line-393"></span><span>           </span><span class="hs-comment">--   type instance F Int = Bool</span><span>
</span><span id="line-394"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-395"></span><span>           </span><span class="hs-comment">--   -- A.hs</span><span>
</span><span id="line-396"></span><span>           </span><span class="hs-comment">--   import B</span><span>
</span><span id="line-397"></span><span>           </span><span class="hs-comment">--   type family F a</span><span>
</span><span id="line-398"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-399"></span><span>           </span><span class="hs-comment">-- When typechecking A, we are NOT allowed to poke the TyThing</span><span>
</span><span id="line-400"></span><span>           </span><span class="hs-comment">-- for F until we have typechecked the family.  Thus, we</span><span>
</span><span id="line-401"></span><span>           </span><span class="hs-comment">-- can't do consistency checking for the instance in B</span><span>
</span><span id="line-402"></span><span>           </span><span class="hs-comment">-- (checkFamInstConsistency is called during renaming).</span><span>
</span><span id="line-403"></span><span>           </span><span class="hs-comment">-- Failing to defer the consistency check lead to #11062.</span><span>
</span><span id="line-404"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-405"></span><span>           </span><span class="hs-comment">-- Additionally, we should also defer consistency checking when</span><span>
</span><span id="line-406"></span><span>           </span><span class="hs-comment">-- type from the hs-boot file of the current module occurs on</span><span>
</span><span id="line-407"></span><span>           </span><span class="hs-comment">-- the left hand side, as we will poke its TyThing when checking</span><span>
</span><span id="line-408"></span><span>           </span><span class="hs-comment">-- for overlap.</span><span>
</span><span id="line-409"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-410"></span><span>           </span><span class="hs-comment">--   -- F.hs</span><span>
</span><span id="line-411"></span><span>           </span><span class="hs-comment">--   type family F a</span><span>
</span><span id="line-412"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-413"></span><span>           </span><span class="hs-comment">--   -- A.hs-boot</span><span>
</span><span id="line-414"></span><span>           </span><span class="hs-comment">--   import F</span><span>
</span><span id="line-415"></span><span>           </span><span class="hs-comment">--   data T</span><span>
</span><span id="line-416"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-417"></span><span>           </span><span class="hs-comment">--   -- B.hs</span><span>
</span><span id="line-418"></span><span>           </span><span class="hs-comment">--   import {-# SOURCE #-} A</span><span>
</span><span id="line-419"></span><span>           </span><span class="hs-comment">--   import F</span><span>
</span><span id="line-420"></span><span>           </span><span class="hs-comment">--   type instance F T = Int</span><span>
</span><span id="line-421"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-422"></span><span>           </span><span class="hs-comment">--   -- A.hs</span><span>
</span><span id="line-423"></span><span>           </span><span class="hs-comment">--   import B</span><span>
</span><span id="line-424"></span><span>           </span><span class="hs-comment">--   data T = MkT</span><span>
</span><span id="line-425"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-426"></span><span>           </span><span class="hs-comment">-- In fact, it is even necessary to defer for occurrences in</span><span>
</span><span id="line-427"></span><span>           </span><span class="hs-comment">-- the RHS, because we may test for *compatibility* in event</span><span>
</span><span id="line-428"></span><span>           </span><span class="hs-comment">-- of an overlap.</span><span>
</span><span id="line-429"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-430"></span><span>           </span><span class="hs-comment">-- Why don't we defer ALL of the checks to later?  Well, many</span><span>
</span><span id="line-431"></span><span>           </span><span class="hs-comment">-- instances aren't involved in the recursive loop at all.  So</span><span>
</span><span id="line-432"></span><span>           </span><span class="hs-comment">-- we might as well check them immediately; and there isn't</span><span>
</span><span id="line-433"></span><span>           </span><span class="hs-comment">-- a good time to check them later in any case: every time</span><span>
</span><span id="line-434"></span><span>           </span><span class="hs-comment">-- we finish kind-checking a type declaration and add it to</span><span>
</span><span id="line-435"></span><span>           </span><span class="hs-comment">-- a context, we *then* consistency check all of the instances</span><span>
</span><span id="line-436"></span><span>           </span><span class="hs-comment">-- which mentioned that type.  We DO want to check instances</span><span>
</span><span id="line-437"></span><span>           </span><span class="hs-comment">-- as quickly as possible, so that we aren't typechecking</span><span>
</span><span id="line-438"></span><span>           </span><span class="hs-comment">-- values with inconsistent axioms in scope.</span><span>
</span><span id="line-439"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-440"></span><span>           </span><span class="hs-comment">-- See also Note [Tying the knot]</span><span>
</span><span id="line-441"></span><span>           </span><span class="hs-comment">-- for why we are doing this at all.</span><span>
</span><span id="line-442"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105365"><span class="annot"><span class="annottext">check_now :: [FamInst]
</span><a href="#local-6989586621681105365"><span class="hs-identifier hs-var hs-var">check_now</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; [FamInst]
</span><a href="GHC.Core.FamInstEnv.html#famInstEnvElts"><span class="hs-identifier hs-var">famInstEnvElts</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105368"><span class="hs-identifier hs-var">env1</span></a></span><span>
</span><span id="line-443"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(FamInst -&gt; TcM ()) -&gt; [FamInst] -&gt; TcM ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#mapM_"><span class="hs-identifier hs-var">mapM_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkForConflicts"><span class="hs-identifier hs-var">checkForConflicts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="GHC.Core.FamInstEnv.html#emptyFamInstEnv"><span class="hs-identifier hs-var">emptyFamInstEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105367"><span class="hs-identifier hs-var">env2</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>           </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105365"><span class="hs-identifier hs-var">check_now</span></a></span><span>
</span><span id="line-444"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(FamInst -&gt; TcM ()) -&gt; [FamInst] -&gt; TcM ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#mapM_"><span class="hs-identifier hs-var">mapM_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkForInjectivityConflicts"><span class="hs-identifier hs-var">checkForInjectivityConflicts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="GHC.Core.FamInstEnv.html#emptyFamInstEnv"><span class="hs-identifier hs-var">emptyFamInstEnv</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105367"><span class="hs-identifier hs-var">env2</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105365"><span class="hs-identifier hs-var">check_now</span></a></span><span>
</span><span id="line-445"></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-446"></span><span>
</span><span id="line-447"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#getFamInsts"><span class="hs-identifier hs-type">getFamInsts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Unit.Module.Env.html#ModuleEnv"><span class="hs-identifier hs-type">ModuleEnv</span></a></span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnv"><span class="hs-identifier hs-type">FamInstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Unit.Types.html#Module"><span class="hs-identifier hs-type">Module</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnv"><span class="hs-identifier hs-type">FamInstEnv</span></a></span><span>
</span><span id="line-448"></span><span id="getFamInsts"><span class="annot"><span class="annottext">getFamInsts :: ModuleEnv FamInstEnv -&gt; Module -&gt; TcM FamInstEnv
</span><a href="GHC.Tc.Instance.Family.html#getFamInsts"><span class="hs-identifier hs-var hs-var">getFamInsts</span></a></span></span><span> </span><span id="local-6989586621681105360"><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105360"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span></span><span> </span><span id="local-6989586621681105359"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105359"><span class="hs-identifier hs-var">mod</span></a></span></span><span>
</span><span id="line-449"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681105358"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105358"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv -&gt; Module -&gt; Maybe FamInstEnv
forall a. ModuleEnv a -&gt; Module -&gt; Maybe a
</span><a href="GHC.Unit.Module.Env.html#lookupModuleEnv"><span class="hs-identifier hs-var">lookupModuleEnv</span></a></span><span> </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv
</span><a href="#local-6989586621681105360"><span class="hs-identifier hs-var">hpt_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105359"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; TcM FamInstEnv
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105358"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-450"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ModIface
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IfG ModIface -&gt; TcRn ModIface
forall a. IfG a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#initIfaceTcRn"><span class="hs-identifier hs-var">initIfaceTcRn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; Module -&gt; IfG ModIface
forall lcl. SDoc -&gt; Module -&gt; IfM lcl ModIface
</span><a href="GHC.Iface.Load.html#loadSysInterface"><span class="hs-identifier hs-var">loadSysInterface</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105354"><span class="hs-identifier hs-var">doc</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105359"><span class="hs-identifier hs-var">mod</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-451"></span><span>                   </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105353"><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105353"><span class="hs-identifier hs-var">eps</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv ExternalPackageState
forall gbl lcl. TcRnIf gbl lcl ExternalPackageState
</span><a href="GHC.Tc.Utils.Monad.html#getEps"><span class="hs-identifier hs-var">getEps</span></a></span><span>
</span><span id="line-452"></span><span>                   </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; TcM FamInstEnv
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Maybe FamInstEnv -&gt; FamInstEnv
forall a. HasCallStack =&gt; String -&gt; Maybe a -&gt; a
</span><a href="GHC.Data.Maybe.html#expectJust"><span class="hs-identifier hs-var">expectJust</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;checkFamInstConsistency&quot;</span></span><span> </span><span class="annot"><span class="annottext">(Maybe FamInstEnv -&gt; FamInstEnv) -&gt; Maybe FamInstEnv -&gt; FamInstEnv
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-453"></span><span>                             </span><span class="annot"><span class="annottext">ModuleEnv FamInstEnv -&gt; Module -&gt; Maybe FamInstEnv
forall a. ModuleEnv a -&gt; Module -&gt; Maybe a
</span><a href="GHC.Unit.Module.Env.html#lookupModuleEnv"><span class="hs-identifier hs-var">lookupModuleEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ExternalPackageState -&gt; ModuleEnv FamInstEnv
</span><a href="GHC.Driver.Types.html#eps_mod_fam_inst_env"><span class="hs-identifier hs-var hs-var">eps_mod_fam_inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105353"><span class="hs-identifier hs-var">eps</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105359"><span class="hs-identifier hs-var">mod</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-454"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-455"></span><span>    </span><span id="local-6989586621681105354"><span class="annot"><span class="annottext">doc :: SDoc
</span><a href="#local-6989586621681105354"><span class="hs-identifier hs-var hs-var">doc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Module -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105359"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is a family-instance module&quot;</span></span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
        Lookup
*                                                                      *
************************************************************************

-}</span><span>
</span><span id="line-465"></span><span>
</span><span id="line-466"></span><span class="hs-comment">-- | If @co :: T ts ~ rep_ty@ then:</span><span>
</span><span id="line-467"></span><span class="hs-comment">--</span><span>
</span><span id="line-468"></span><span class="hs-comment">-- &gt; instNewTyCon_maybe T ts = Just (rep_ty, co)</span><span>
</span><span id="line-469"></span><span class="hs-comment">--</span><span>
</span><span id="line-470"></span><span class="hs-comment">-- Checks for a newtype, and for being saturated</span><span>
</span><span id="line-471"></span><span class="hs-comment">-- Just like Coercion.instNewTyCon_maybe, but returns a TcCoercion</span><span>
</span><span id="line-472"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcInstNewTyCon_maybe"><span class="hs-identifier hs-type">tcInstNewTyCon_maybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-473"></span><span id="tcInstNewTyCon_maybe"><span class="annot"><span class="annottext">tcInstNewTyCon_maybe :: TyCon -&gt; [Type] -&gt; Maybe (Type, TcCoercion)
</span><a href="GHC.Tc.Instance.Family.html#tcInstNewTyCon_maybe"><span class="hs-identifier hs-var hs-var">tcInstNewTyCon_maybe</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [Type] -&gt; Maybe (Type, TcCoercion)
</span><a href="GHC.Core.Coercion.html#instNewTyCon_maybe"><span class="hs-identifier hs-var">instNewTyCon_maybe</span></a></span><span>
</span><span id="line-474"></span><span>
</span><span id="line-475"></span><span class="hs-comment">-- | Like 'tcLookupDataFamInst_maybe', but returns the arguments back if</span><span>
</span><span id="line-476"></span><span class="hs-comment">-- there is no data family to unwrap.</span><span>
</span><span id="line-477"></span><span class="hs-comment">-- Returns a Representational coercion</span><span>
</span><span id="line-478"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst"><span class="hs-identifier hs-type">tcLookupDataFamInst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-479"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-480"></span><span id="tcLookupDataFamInst"><span class="annot"><span class="annottext">tcLookupDataFamInst :: (FamInstEnv, FamInstEnv)
-&gt; TyCon -&gt; [Type] -&gt; (TyCon, [Type], TcCoercion)
</span><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst"><span class="hs-identifier hs-var hs-var">tcLookupDataFamInst</span></a></span></span><span> </span><span id="local-6989586621681105344"><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105344"><span class="hs-identifier hs-var">fam_inst_envs</span></a></span></span><span> </span><span id="local-6989586621681105343"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105343"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681105342"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105342"><span class="hs-identifier hs-var">tc_args</span></a></span></span><span>
</span><span id="line-481"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105341"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105341"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105340"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105340"><span class="hs-identifier hs-var">rep_args</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105339"><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105339"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-482"></span><span>      </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
-&gt; TyCon -&gt; [Type] -&gt; Maybe (TyCon, [Type], TcCoercion)
</span><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst_maybe"><span class="hs-identifier hs-var">tcLookupDataFamInst_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105344"><span class="hs-identifier hs-var">fam_inst_envs</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105343"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105342"><span class="hs-identifier hs-var">tc_args</span></a></span><span>
</span><span id="line-483"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105341"><span class="hs-identifier hs-var">rep_tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105340"><span class="hs-identifier hs-var">rep_args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105339"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-484"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-485"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105343"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105342"><span class="hs-identifier hs-var">tc_args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Type -&gt; TcCoercion
</span><a href="GHC.Core.Coercion.html#mkRepReflCo"><span class="hs-identifier hs-var">mkRepReflCo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [Type] -&gt; Type
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105343"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105342"><span class="hs-identifier hs-var">tc_args</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-486"></span><span>
</span><span id="line-487"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst_maybe"><span class="hs-identifier hs-type">tcLookupDataFamInst_maybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-488"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-489"></span><span class="hs-comment">-- ^ Converts a data family type (eg F [a]) to its representation type (eg FList a)</span><span>
</span><span id="line-490"></span><span class="hs-comment">-- and returns a coercion between the two: co :: F [a] ~R FList a.</span><span>
</span><span id="line-491"></span><span id="tcLookupDataFamInst_maybe"><span class="annot"><span class="annottext">tcLookupDataFamInst_maybe :: (FamInstEnv, FamInstEnv)
-&gt; TyCon -&gt; [Type] -&gt; Maybe (TyCon, [Type], TcCoercion)
</span><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst_maybe"><span class="hs-identifier hs-var hs-var">tcLookupDataFamInst_maybe</span></a></span></span><span> </span><span id="local-6989586621681105336"><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105336"><span class="hs-identifier hs-var">fam_inst_envs</span></a></span></span><span> </span><span id="local-6989586621681105335"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105335"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681105334"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105334"><span class="hs-identifier hs-var">tc_args</span></a></span></span><span>
</span><span id="line-492"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; WhetherHasFamInst
</span><a href="GHC.Core.TyCon.html#isDataFamilyTyCon"><span class="hs-identifier hs-var">isDataFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105335"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-493"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105332"><span class="annot"><span class="annottext">FamInstMatch
</span><a href="#local-6989586621681105332"><span class="hs-identifier hs-var">match</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span class="annot"><span class="annottext">[FamInstMatch]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; TyCon -&gt; [Type] -&gt; [FamInstMatch]
</span><a href="GHC.Core.FamInstEnv.html#lookupFamInstEnv"><span class="hs-identifier hs-var">lookupFamInstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105336"><span class="hs-identifier hs-var">fam_inst_envs</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105335"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105334"><span class="hs-identifier hs-var">tc_args</span></a></span><span>
</span><span id="line-494"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstMatch"><span class="hs-identifier hs-type">FamInstMatch</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fim_instance :: FamInstMatch -&gt; FamInst
</span><a href="GHC.Core.FamInstEnv.html#fim_instance"><span class="hs-identifier hs-var">fim_instance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105328"><span class="annot"><span class="annottext">rep_fam :: FamInst
</span><a href="#local-6989586621681105328"><span class="hs-identifier hs-var">rep_fam</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fi_axiom :: FamInst -&gt; CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#fi_axiom"><span class="hs-identifier hs-var">fi_axiom</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105327"><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105327"><span class="hs-identifier hs-var">ax</span></a></span></span><span>
</span><span id="line-495"></span><span>                                                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fi_cvs :: FamInst -&gt; [TyCoVar]
</span><a href="GHC.Core.FamInstEnv.html#fi_cvs"><span class="hs-identifier hs-var">fi_cvs</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105326"><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105326"><span class="hs-identifier hs-var">cvs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-496"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fim_tys :: FamInstMatch -&gt; [Type]
</span><a href="GHC.Core.FamInstEnv.html#fim_tys"><span class="hs-identifier hs-var">fim_tys</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105324"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105324"><span class="hs-identifier hs-var">rep_args</span></a></span></span><span>
</span><span id="line-497"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fim_cos :: FamInstMatch -&gt; [TcCoercion]
</span><a href="GHC.Core.FamInstEnv.html#fim_cos"><span class="hs-identifier hs-var">fim_cos</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105322"><span class="annot"><span class="annottext">[TcCoercion]
</span><a href="#local-6989586621681105322"><span class="hs-identifier hs-var">rep_cos</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FamInstMatch
</span><a href="#local-6989586621681105332"><span class="hs-identifier hs-var">match</span></a></span><span>
</span><span id="line-498"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105321"><span class="annot"><span class="annottext">rep_tc :: TyCon
</span><a href="#local-6989586621681105321"><span class="hs-identifier hs-var hs-var">rep_tc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; TyCon
</span><a href="GHC.Core.FamInstEnv.html#dataFamInstRepTyCon"><span class="hs-identifier hs-var">dataFamInstRepTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105328"><span class="hs-identifier hs-var">rep_fam</span></a></span><span>
</span><span id="line-499"></span><span>        </span><span id="local-6989586621681105319"><span class="annot"><span class="annottext">co :: TcCoercion
</span><a href="#local-6989586621681105319"><span class="hs-identifier hs-var hs-var">co</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Role -&gt; CoAxiom Unbranched -&gt; [Type] -&gt; [TcCoercion] -&gt; TcCoercion
</span><a href="GHC.Core.Coercion.html#mkUnbranchedAxInstCo"><span class="hs-identifier hs-var">mkUnbranchedAxInstCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Representational"><span class="hs-identifier hs-var">Representational</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105327"><span class="hs-identifier hs-var">ax</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105324"><span class="hs-identifier hs-var">rep_args</span></a></span><span>
</span><span id="line-500"></span><span>                                      </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyCoVar] -&gt; [TcCoercion]
</span><a href="GHC.Core.Coercion.html#mkCoVarCos"><span class="hs-identifier hs-var">mkCoVarCos</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoVar]
</span><a href="#local-6989586621681105326"><span class="hs-identifier hs-var">cvs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-501"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">null</span><span> </span><span class="hs-identifier">rep_cos</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- See Note [Constrained family instances] in GHC.Core.FamInstEnv</span><span>
</span><span id="line-502"></span><span>    </span><span class="annot"><span class="annottext">(TyCon, [Type], TcCoercion) -&gt; Maybe (TyCon, [Type], TcCoercion)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105321"><span class="hs-identifier hs-var">rep_tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105324"><span class="hs-identifier hs-var">rep_args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105319"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-503"></span><span>
</span><span id="line-504"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-505"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (TyCon, [Type], TcCoercion)
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-506"></span><span>
</span><span id="line-507"></span><span class="hs-comment">-- | 'tcTopNormaliseNewTypeTF_maybe' gets rid of top-level newtypes,</span><span>
</span><span id="line-508"></span><span class="hs-comment">-- potentially looking through newtype /instances/.</span><span>
</span><span id="line-509"></span><span class="hs-comment">--</span><span>
</span><span id="line-510"></span><span class="hs-comment">-- It is only used by the type inference engine (specifically, when</span><span>
</span><span id="line-511"></span><span class="hs-comment">-- solving representational equality), and hence it is careful to unwrap</span><span>
</span><span id="line-512"></span><span class="hs-comment">-- only if the relevant data constructor is in scope.  That's why</span><span>
</span><span id="line-513"></span><span class="hs-comment">-- it get a GlobalRdrEnv argument.</span><span>
</span><span id="line-514"></span><span class="hs-comment">--</span><span>
</span><span id="line-515"></span><span class="hs-comment">-- It is careful not to unwrap data/newtype instances if it can't</span><span>
</span><span id="line-516"></span><span class="hs-comment">-- continue unwrapping.  Such care is necessary for proper error</span><span>
</span><span id="line-517"></span><span class="hs-comment">-- messages.</span><span>
</span><span id="line-518"></span><span class="hs-comment">--</span><span>
</span><span id="line-519"></span><span class="hs-comment">-- It does not look through type families.</span><span>
</span><span id="line-520"></span><span class="hs-comment">-- It does not normalise arguments to a tycon.</span><span>
</span><span id="line-521"></span><span class="hs-comment">--</span><span>
</span><span id="line-522"></span><span class="hs-comment">-- If the result is Just (rep_ty, (co, gres), rep_ty), then</span><span>
</span><span id="line-523"></span><span class="hs-comment">--    co : ty ~R rep_ty</span><span>
</span><span id="line-524"></span><span class="hs-comment">--    gres are the GREs for the data constructors that</span><span>
</span><span id="line-525"></span><span class="hs-comment">--                          had to be in scope</span><span>
</span><span id="line-526"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcTopNormaliseNewTypeTF_maybe"><span class="hs-identifier hs-type">tcTopNormaliseNewTypeTF_maybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span>
</span><span id="line-527"></span><span>                              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html#GlobalRdrEnv"><span class="hs-identifier hs-type">GlobalRdrEnv</span></a></span><span>
</span><span id="line-528"></span><span>                              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>
</span><span id="line-529"></span><span>                              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html#GlobalRdrElt"><span class="hs-identifier hs-type">GlobalRdrElt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-530"></span><span id="tcTopNormaliseNewTypeTF_maybe"><span class="annot"><span class="annottext">tcTopNormaliseNewTypeTF_maybe :: (FamInstEnv, FamInstEnv)
-&gt; GlobalRdrEnv
-&gt; Type
-&gt; Maybe ((Bag GlobalRdrElt, TcCoercion), Type)
</span><a href="GHC.Tc.Instance.Family.html#tcTopNormaliseNewTypeTF_maybe"><span class="hs-identifier hs-var hs-var">tcTopNormaliseNewTypeTF_maybe</span></a></span></span><span> </span><span id="local-6989586621681105310"><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105310"><span class="hs-identifier hs-var">faminsts</span></a></span></span><span> </span><span id="local-6989586621681105309"><span class="annot"><span class="annottext">GlobalRdrEnv
</span><a href="#local-6989586621681105309"><span class="hs-identifier hs-var">rdr_env</span></a></span></span><span> </span><span id="local-6989586621681105308"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105308"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-531"></span><span class="hs-comment">-- cf. FamInstEnv.topNormaliseType_maybe and Coercion.topNormaliseNewType_maybe</span><span>
</span><span id="line-532"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
-&gt; ((Bag GlobalRdrElt, TcCoercion)
    -&gt; (Bag GlobalRdrElt, TcCoercion)
    -&gt; (Bag GlobalRdrElt, TcCoercion))
-&gt; Type
-&gt; Maybe ((Bag GlobalRdrElt, TcCoercion), Type)
forall ev.
NormaliseStepper ev -&gt; (ev -&gt; ev -&gt; ev) -&gt; Type -&gt; Maybe (ev, Type)
</span><a href="GHC.Core.Coercion.html#topNormaliseTypeX"><span class="hs-identifier hs-var">topNormaliseTypeX</span></a></span><span> </span><span class="annot"><span class="annottext">NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105306"><span class="hs-identifier hs-var">stepper</span></a></span><span> </span><span class="annot"><span class="annottext">(Bag GlobalRdrElt, TcCoercion)
-&gt; (Bag GlobalRdrElt, TcCoercion) -&gt; (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105305"><span class="hs-identifier hs-var">plus</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105308"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-533"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-534"></span><span>    </span><span class="annot"><a href="#local-6989586621681105305"><span class="hs-identifier hs-type">plus</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html#GlobalRdrElt"><span class="hs-identifier hs-type">GlobalRdrElt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html#GlobalRdrElt"><span class="hs-identifier hs-type">GlobalRdrElt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-535"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html#GlobalRdrElt"><span class="hs-identifier hs-type">GlobalRdrElt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-536"></span><span>    </span><span id="local-6989586621681105305"><span class="annot"><span class="annottext">plus :: (Bag GlobalRdrElt, TcCoercion)
-&gt; (Bag GlobalRdrElt, TcCoercion) -&gt; (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105305"><span class="hs-identifier hs-var hs-var">plus</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105304"><span class="annot"><span class="annottext">Bag GlobalRdrElt
</span><a href="#local-6989586621681105304"><span class="hs-identifier hs-var">gres1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105303"><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105303"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105302"><span class="annot"><span class="annottext">Bag GlobalRdrElt
</span><a href="#local-6989586621681105302"><span class="hs-identifier hs-var">gres2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105301"><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105301"><span class="hs-identifier hs-var">co2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">Bag GlobalRdrElt
</span><a href="#local-6989586621681105304"><span class="hs-identifier hs-var">gres1</span></a></span><span> </span><span class="annot"><span class="annottext">Bag GlobalRdrElt -&gt; Bag GlobalRdrElt -&gt; Bag GlobalRdrElt
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">Bag GlobalRdrElt
</span><a href="#local-6989586621681105302"><span class="hs-identifier hs-var">gres2</span></a></span><span>
</span><span id="line-537"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105303"><span class="hs-identifier hs-var">co1</span></a></span><span> </span><span class="annot"><span class="annottext">TcCoercion -&gt; TcCoercion -&gt; TcCoercion
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105301"><span class="hs-identifier hs-var">co2</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-538"></span><span>
</span><span id="line-539"></span><span>    </span><span class="annot"><a href="#local-6989586621681105306"><span class="hs-identifier hs-type">stepper</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.html#NormaliseStepper"><span class="hs-identifier hs-type">NormaliseStepper</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html#GlobalRdrElt"><span class="hs-identifier hs-type">GlobalRdrElt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-540"></span><span>    </span><span id="local-6989586621681105306"><span class="annot"><span class="annottext">stepper :: NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105306"><span class="hs-identifier hs-var hs-var">stepper</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105299"><span class="hs-identifier hs-var">unwrap_newtype</span></a></span><span> </span><span class="annot"><span class="annottext">NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
-&gt; NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
-&gt; NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
forall ev.
NormaliseStepper ev -&gt; NormaliseStepper ev -&gt; NormaliseStepper ev
</span><a href="GHC.Core.Coercion.html#composeSteppers"><span class="hs-operator hs-var">`composeSteppers`</span></a></span><span> </span><span class="annot"><span class="annottext">NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105297"><span class="hs-identifier hs-var">unwrap_newtype_instance</span></a></span><span>
</span><span id="line-541"></span><span>
</span><span id="line-542"></span><span>    </span><span class="hs-comment">-- For newtype instances we take a double step or nothing, so that</span><span>
</span><span id="line-543"></span><span>    </span><span class="hs-comment">-- we don't return the representation type of the newtype instance,</span><span>
</span><span id="line-544"></span><span>    </span><span class="hs-comment">-- which would lead to terrible error messages</span><span>
</span><span id="line-545"></span><span>    </span><span id="local-6989586621681105297"><span class="annot"><span class="annottext">unwrap_newtype_instance :: NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105297"><span class="hs-identifier hs-var hs-var">unwrap_newtype_instance</span></a></span></span><span> </span><span id="local-6989586621681105296"><span class="annot"><span class="annottext">RecTcChecker
</span><a href="#local-6989586621681105296"><span class="hs-identifier hs-var">rec_nts</span></a></span></span><span> </span><span id="local-6989586621681105295"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105295"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681105294"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105294"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-546"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105293"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105293"><span class="hs-identifier hs-var">tc'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105292"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105292"><span class="hs-identifier hs-var">tys'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105291"><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105291"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
-&gt; TyCon -&gt; [Type] -&gt; Maybe (TyCon, [Type], TcCoercion)
</span><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst_maybe"><span class="hs-identifier hs-var">tcLookupDataFamInst_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105310"><span class="hs-identifier hs-var">faminsts</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105295"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105294"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-547"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Bag GlobalRdrElt, TcCoercion) -&gt; (Bag GlobalRdrElt, TcCoercion))
-&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
-&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
forall ev1 ev2.
(ev1 -&gt; ev2) -&gt; NormaliseStepResult ev1 -&gt; NormaliseStepResult ev2
</span><a href="GHC.Core.Coercion.html#mapStepResult"><span class="hs-identifier hs-var">mapStepResult</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621681105289"><span class="annot"><span class="annottext">Bag GlobalRdrElt
</span><a href="#local-6989586621681105289"><span class="hs-identifier hs-var">gres</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105288"><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105288"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag GlobalRdrElt
</span><a href="#local-6989586621681105289"><span class="hs-identifier hs-var">gres</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105291"><span class="hs-identifier hs-var">co</span></a></span><span> </span><span class="annot"><span class="annottext">TcCoercion -&gt; TcCoercion -&gt; TcCoercion
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105288"><span class="hs-identifier hs-var">co1</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
 -&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion))
-&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
-&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-548"></span><span>        </span><span class="annot"><span class="annottext">NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105299"><span class="hs-identifier hs-var">unwrap_newtype</span></a></span><span> </span><span class="annot"><span class="annottext">RecTcChecker
</span><a href="#local-6989586621681105296"><span class="hs-identifier hs-var">rec_nts</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105293"><span class="hs-identifier hs-var">tc'</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105292"><span class="hs-identifier hs-var">tys'</span></a></span><span>
</span><span id="line-549"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
forall ev. NormaliseStepResult ev
</span><a href="GHC.Core.Coercion.html#NS_Done"><span class="hs-identifier hs-var">NS_Done</span></a></span><span>
</span><span id="line-550"></span><span>
</span><span id="line-551"></span><span>    </span><span id="local-6989586621681105299"><span class="annot"><span class="annottext">unwrap_newtype :: NormaliseStepper (Bag GlobalRdrElt, TcCoercion)
</span><a href="#local-6989586621681105299"><span class="hs-identifier hs-var hs-var">unwrap_newtype</span></a></span></span><span> </span><span id="local-6989586621681105286"><span class="annot"><span class="annottext">RecTcChecker
</span><a href="#local-6989586621681105286"><span class="hs-identifier hs-var">rec_nts</span></a></span></span><span> </span><span id="local-6989586621681105285"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105285"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681105284"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105284"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-552"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681105283"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621681105283"><span class="hs-identifier hs-var">con</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Maybe DataCon
</span><a href="GHC.Core.TyCon.html#newTyConDataCon_maybe"><span class="hs-identifier hs-var">newTyConDataCon_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105285"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-553"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681105281"><span class="annot"><span class="annottext">GlobalRdrElt
</span><a href="#local-6989586621681105281"><span class="hs-identifier hs-var">gre</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">GlobalRdrEnv -&gt; Name -&gt; Maybe GlobalRdrElt
</span><a href="GHC.Types.Name.Reader.html#lookupGRE_Name"><span class="hs-identifier hs-var">lookupGRE_Name</span></a></span><span> </span><span class="annot"><span class="annottext">GlobalRdrEnv
</span><a href="#local-6989586621681105309"><span class="hs-identifier hs-var">rdr_env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DataCon -&gt; Name
</span><a href="GHC.Core.DataCon.html#dataConName"><span class="hs-identifier hs-var">dataConName</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621681105283"><span class="hs-identifier hs-var">con</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-554"></span><span>           </span><span class="hs-comment">-- This is where we check that the</span><span>
</span><span id="line-555"></span><span>           </span><span class="hs-comment">-- data constructor is in scope</span><span>
</span><span id="line-556"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TcCoercion -&gt; (Bag GlobalRdrElt, TcCoercion))
-&gt; NormaliseStepResult TcCoercion
-&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
forall ev1 ev2.
(ev1 -&gt; ev2) -&gt; NormaliseStepResult ev1 -&gt; NormaliseStepResult ev2
</span><a href="GHC.Core.Coercion.html#mapStepResult"><span class="hs-identifier hs-var">mapStepResult</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681105279"><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105279"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GlobalRdrElt -&gt; Bag GlobalRdrElt
forall a. a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unitBag"><span class="hs-identifier hs-var">unitBag</span></a></span><span> </span><span class="annot"><span class="annottext">GlobalRdrElt
</span><a href="#local-6989586621681105281"><span class="hs-identifier hs-var">gre</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcCoercion
</span><a href="#local-6989586621681105279"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(NormaliseStepResult TcCoercion
 -&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion))
-&gt; NormaliseStepResult TcCoercion
-&gt; NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-557"></span><span>        </span><span class="annot"><span class="annottext">NormaliseStepper TcCoercion
</span><a href="GHC.Core.Coercion.html#unwrapNewTypeStepper"><span class="hs-identifier hs-var">unwrapNewTypeStepper</span></a></span><span> </span><span class="annot"><span class="annottext">RecTcChecker
</span><a href="#local-6989586621681105286"><span class="hs-identifier hs-var">rec_nts</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105285"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105284"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-558"></span><span>
</span><span id="line-559"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-560"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NormaliseStepResult (Bag GlobalRdrElt, TcCoercion)
forall ev. NormaliseStepResult ev
</span><a href="GHC.Core.Coercion.html#NS_Done"><span class="hs-identifier hs-var">NS_Done</span></a></span><span>
</span><span id="line-561"></span><span>
</span><span id="line-562"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
        Extending the family instance environment
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-569"></span><span>
</span><span id="line-570"></span><span class="hs-comment">-- Add new locally-defined family instances, checking consistency with</span><span>
</span><span id="line-571"></span><span class="hs-comment">-- previous locally-defined family instances as well as all instances</span><span>
</span><span id="line-572"></span><span class="hs-comment">-- available from imported modules. This requires loading all of our</span><span>
</span><span id="line-573"></span><span class="hs-comment">-- imports that define family instances (if we haven't loaded them already).</span><span>
</span><span id="line-574"></span><span id="local-6989586621681105616"><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcExtendLocalFamInstEnv"><span class="hs-identifier hs-type">tcExtendLocalFamInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681105616"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681105616"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-575"></span><span>
</span><span id="line-576"></span><span class="hs-comment">-- If we weren't actually given any instances to add, then we don't want</span><span>
</span><span id="line-577"></span><span class="hs-comment">-- to go to the bother of loading family instance module dependencies.</span><span>
</span><span id="line-578"></span><span id="tcExtendLocalFamInstEnv"><span class="annot"><span class="annottext">tcExtendLocalFamInstEnv :: forall a. [FamInst] -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Instance.Family.html#tcExtendLocalFamInstEnv"><span class="hs-identifier hs-var hs-var">tcExtendLocalFamInstEnv</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621681105272"><span class="annot"><span class="annottext">TcM a
</span><a href="#local-6989586621681105272"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcM a
</span><a href="#local-6989586621681105272"><span class="hs-identifier hs-var">thing_inside</span></a></span><span>
</span><span id="line-579"></span><span>
</span><span id="line-580"></span><span class="hs-comment">-- Otherwise proceed...</span><span>
</span><span id="line-581"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcExtendLocalFamInstEnv"><span class="hs-identifier hs-var">tcExtendLocalFamInstEnv</span></a></span><span> </span><span id="local-6989586621681105271"><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105271"><span class="hs-identifier hs-var">fam_insts</span></a></span></span><span> </span><span id="local-6989586621681105270"><span class="annot"><span class="annottext">TcM a
</span><a href="#local-6989586621681105270"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span>
</span><span id="line-582"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-comment">-- Load family-instance modules &quot;below&quot; this module, so that</span><span>
</span><span id="line-583"></span><span>        </span><span class="hs-comment">-- allLocalFamInst can check for consistency with them</span><span>
</span><span id="line-584"></span><span>        </span><span class="hs-comment">-- See Note [The type family instance consistency story]</span><span>
</span><span id="line-585"></span><span>        </span><span class="annot"><span class="annottext">[FamInst] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#loadDependentFamInstModules"><span class="hs-identifier hs-var">loadDependentFamInstModules</span></a></span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105271"><span class="hs-identifier hs-var">fam_insts</span></a></span><span>
</span><span id="line-586"></span><span>
</span><span id="line-587"></span><span>        </span><span class="hs-comment">-- Now add the instances one by one</span><span>
</span><span id="line-588"></span><span>      </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105268"><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105268"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
</span><a href="GHC.Tc.Utils.Monad.html#getGblEnv"><span class="hs-identifier hs-var">getGblEnv</span></a></span><span>
</span><span id="line-589"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105266"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105266"><span class="hs-identifier hs-var">inst_env'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105265"><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105265"><span class="hs-identifier hs-var">fam_insts'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">((FamInstEnv, [FamInst])
 -&gt; FamInst
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (FamInstEnv, [FamInst]))
-&gt; (FamInstEnv, [FamInst])
-&gt; [FamInst]
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (FamInstEnv, [FamInst])
forall (t :: * -&gt; *) (m :: * -&gt; *) b a.
(Foldable t, Monad m) =&gt;
(b -&gt; a -&gt; m b) -&gt; b -&gt; t a -&gt; m b
</span><a href="../../base/src/Data.Foldable.html#foldlM"><span class="hs-identifier hs-var">foldlM</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, [FamInst])
-&gt; FamInst -&gt; IOEnv (Env TcGblEnv TcLclEnv) (FamInstEnv, [FamInst])
</span><a href="GHC.Tc.Instance.Family.html#addLocalFamInst"><span class="hs-identifier hs-var">addLocalFamInst</span></a></span><span>
</span><span id="line-590"></span><span>                                       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcGblEnv -&gt; FamInstEnv
</span><a href="GHC.Tc.Types.html#tcg_fam_inst_env"><span class="hs-identifier hs-var hs-var">tcg_fam_inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105268"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcGblEnv -&gt; [FamInst]
</span><a href="GHC.Tc.Types.html#tcg_fam_insts"><span class="hs-identifier hs-var hs-var">tcg_fam_insts</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105268"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-591"></span><span>                                       </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105271"><span class="hs-identifier hs-var">fam_insts</span></a></span><span>
</span><span id="line-592"></span><span>
</span><span id="line-593"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105260"><span class="annot"><span class="annottext">env' :: TcGblEnv
</span><a href="#local-6989586621681105260"><span class="hs-identifier hs-var hs-var">env'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105268"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">tcg_fam_insts :: [FamInst]
</span><a href="GHC.Tc.Types.html#tcg_fam_insts"><span class="hs-identifier hs-var">tcg_fam_insts</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105265"><span class="hs-identifier hs-var">fam_insts'</span></a></span><span>
</span><span id="line-594"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">tcg_fam_inst_env :: FamInstEnv
</span><a href="GHC.Tc.Types.html#tcg_fam_inst_env"><span class="hs-identifier hs-var">tcg_fam_inst_env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105266"><span class="hs-identifier hs-var">inst_env'</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-595"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcGblEnv -&gt; TcM a -&gt; TcM a
forall gbl lcl a. gbl -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#setGblEnv"><span class="hs-identifier hs-var">setGblEnv</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105260"><span class="hs-identifier hs-var">env'</span></a></span><span> </span><span class="annot"><span class="annottext">TcM a
</span><a href="#local-6989586621681105270"><span class="hs-identifier hs-var">thing_inside</span></a></span><span>
</span><span id="line-596"></span><span>      </span><span class="hs-special">}</span><span>
</span><span id="line-597"></span><span>
</span><span id="line-598"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#loadDependentFamInstModules"><span class="hs-identifier hs-type">loadDependentFamInstModules</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-599"></span><span class="hs-comment">-- Load family-instance modules &quot;below&quot; this module, so that</span><span>
</span><span id="line-600"></span><span class="hs-comment">-- allLocalFamInst can check for consistency with them</span><span>
</span><span id="line-601"></span><span class="hs-comment">-- See Note [The type family instance consistency story]</span><span>
</span><span id="line-602"></span><span id="loadDependentFamInstModules"><span class="annot"><span class="annottext">loadDependentFamInstModules :: [FamInst] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#loadDependentFamInstModules"><span class="hs-identifier hs-var hs-var">loadDependentFamInstModules</span></a></span></span><span> </span><span id="local-6989586621681105258"><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105258"><span class="hs-identifier hs-var">fam_insts</span></a></span></span><span>
</span><span id="line-603"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681105257"><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105257"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
</span><a href="GHC.Tc.Utils.Monad.html#getGblEnv"><span class="hs-identifier hs-var">getGblEnv</span></a></span><span>
</span><span id="line-604"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105256"><span class="annot"><span class="annottext">this_mod :: Module
</span><a href="#local-6989586621681105256"><span class="hs-identifier hs-var hs-var">this_mod</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcGblEnv -&gt; Module
</span><a href="GHC.Tc.Types.html#tcg_mod"><span class="hs-identifier hs-var hs-var">tcg_mod</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105257"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-605"></span><span>            </span><span id="local-6989586621681105254"><span class="annot"><span class="annottext">imports :: ImportAvails
</span><a href="#local-6989586621681105254"><span class="hs-identifier hs-var hs-var">imports</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcGblEnv -&gt; ImportAvails
</span><a href="GHC.Tc.Types.html#tcg_imports"><span class="hs-identifier hs-var hs-var">tcg_imports</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105257"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-606"></span><span>
</span><span id="line-607"></span><span>            </span><span id="local-6989586621681105252"><span class="annot"><span class="annottext">want_module :: Module -&gt; WhetherHasFamInst
</span><a href="#local-6989586621681105252"><span class="hs-identifier hs-var hs-var">want_module</span></a></span></span><span> </span><span id="local-6989586621681105251"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105251"><span class="hs-identifier hs-var">mod</span></a></span></span><span>  </span><span class="hs-comment">-- See Note [Home package family instances]</span><span>
</span><span id="line-608"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105251"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; Module -&gt; WhetherHasFamInst
forall a. Eq a =&gt; a -&gt; a -&gt; WhetherHasFamInst
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105256"><span class="hs-identifier hs-var">this_mod</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-609"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105250"><span class="hs-identifier hs-var">home_fams_only</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Module -&gt; Unit
forall unit. GenModule unit -&gt; unit
</span><a href="GHC.Unit.Types.html#moduleUnit"><span class="hs-identifier hs-var hs-var">moduleUnit</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105251"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="annot"><span class="annottext">Unit -&gt; Unit -&gt; WhetherHasFamInst
forall a. Eq a =&gt; a -&gt; a -&gt; WhetherHasFamInst
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Module -&gt; Unit
forall unit. GenModule unit -&gt; unit
</span><a href="GHC.Unit.Types.html#moduleUnit"><span class="hs-identifier hs-var hs-var">moduleUnit</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105256"><span class="hs-identifier hs-var">this_mod</span></a></span><span>
</span><span id="line-610"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-611"></span><span>            </span><span id="local-6989586621681105250"><span class="annot"><span class="annottext">home_fams_only :: WhetherHasFamInst
</span><a href="#local-6989586621681105250"><span class="hs-identifier hs-var hs-var">home_fams_only</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FamInst -&gt; WhetherHasFamInst) -&gt; [FamInst] -&gt; WhetherHasFamInst
forall (t :: * -&gt; *) a.
Foldable t =&gt;
(a -&gt; WhetherHasFamInst) -&gt; t a -&gt; WhetherHasFamInst
</span><a href="../../base/src/Data.Foldable.html#all"><span class="hs-identifier hs-var">all</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; Name -&gt; WhetherHasFamInst
</span><a href="GHC.Types.Name.html#nameIsHomePackage"><span class="hs-identifier hs-var">nameIsHomePackage</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105256"><span class="hs-identifier hs-var">this_mod</span></a></span><span> </span><span class="annot"><span class="annottext">(Name -&gt; WhetherHasFamInst)
-&gt; (FamInst -&gt; Name) -&gt; FamInst -&gt; WhetherHasFamInst
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; Name
</span><a href="GHC.Core.FamInstEnv.html#fi_fam"><span class="hs-identifier hs-var hs-var">fi_fam</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105258"><span class="hs-identifier hs-var">fam_insts</span></a></span><span>
</span><span id="line-612"></span><span>
</span><span id="line-613"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; [Module] -&gt; TcM ()
</span><a href="GHC.Iface.Load.html#loadModuleInterfaces"><span class="hs-identifier hs-var">loadModuleInterfaces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Loading family-instance modules&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([Module] -&gt; TcM ()) -&gt; [Module] -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-614"></span><span>        </span><span class="annot"><span class="annottext">(Module -&gt; WhetherHasFamInst) -&gt; [Module] -&gt; [Module]
forall a. (a -&gt; WhetherHasFamInst) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; WhetherHasFamInst
</span><a href="#local-6989586621681105252"><span class="hs-identifier hs-var">want_module</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ImportAvails -&gt; [Module]
</span><a href="GHC.Tc.Types.html#imp_finsts"><span class="hs-identifier hs-var hs-var">imp_finsts</span></a></span><span> </span><span class="annot"><span class="annottext">ImportAvails
</span><a href="#local-6989586621681105254"><span class="hs-identifier hs-var">imports</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-615"></span><span>
</span><span id="line-616"></span><span class="hs-comment">{- Note [Home package family instances]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Optimization: If we're only defining type family instances
for type families *defined in the home package*, then we
only have to load interface files that belong to the home
package. The reason is that there's no recursion between
packages, so modules in other packages can't possibly define
instances for our type families.

(Within the home package, we could import a module M that
imports us via an hs-boot file, and thereby defines an
instance of a type family defined in this module. So we can't
apply the same logic to avoid reading any interface files at
all, when we define an instances for type family defined in
the current module.
-}</span><span>
</span><span id="line-632"></span><span>
</span><span id="line-633"></span><span class="hs-comment">-- Check that the proposed new instance is OK,</span><span>
</span><span id="line-634"></span><span class="hs-comment">-- and then add it to the home inst env</span><span>
</span><span id="line-635"></span><span class="hs-comment">-- This must be lazy in the fam_inst arguments, see Note [Lazy axiom match]</span><span>
</span><span id="line-636"></span><span class="hs-comment">-- in GHC.Core.FamInstEnv</span><span>
</span><span id="line-637"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#addLocalFamInst"><span class="hs-identifier hs-type">addLocalFamInst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnv"><span class="hs-identifier hs-type">FamInstEnv</span></a></span><span class="hs-special">,</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-638"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span>
</span><span id="line-639"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnv"><span class="hs-identifier hs-type">FamInstEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-640"></span><span id="addLocalFamInst"><span class="annot"><span class="annottext">addLocalFamInst :: (FamInstEnv, [FamInst])
-&gt; FamInst -&gt; IOEnv (Env TcGblEnv TcLclEnv) (FamInstEnv, [FamInst])
</span><a href="GHC.Tc.Instance.Family.html#addLocalFamInst"><span class="hs-identifier hs-var hs-var">addLocalFamInst</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105244"><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105244"><span class="hs-identifier hs-var">home_fie</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105243"><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105243"><span class="hs-identifier hs-var">my_fis</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681105242"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span></span><span>
</span><span id="line-641"></span><span>        </span><span class="hs-comment">-- home_fie includes home package and this module</span><span>
</span><span id="line-642"></span><span>        </span><span class="hs-comment">-- my_fies is just the ones from this module</span><span>
</span><span id="line-643"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;addLocalFamInst&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInst -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-644"></span><span>
</span><span id="line-645"></span><span>           </span><span class="hs-comment">-- Unlike the case of class instances, don't override existing</span><span>
</span><span id="line-646"></span><span>           </span><span class="hs-comment">-- instances in GHCi; it's unsound. See #7102.</span><span>
</span><span id="line-647"></span><span>
</span><span id="line-648"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105241"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105241"><span class="hs-identifier hs-var">mod</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -&gt; *). HasModule m =&gt; m Module
</span><a href="GHC.Unit.Module.html#getModule"><span class="hs-identifier hs-var">getModule</span></a></span><span>
</span><span id="line-649"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;alfi&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Module -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621681105241"><span class="hs-identifier hs-var">mod</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-650"></span><span>
</span><span id="line-651"></span><span>           </span><span class="hs-comment">-- Fetch imported instances, so that we report</span><span>
</span><span id="line-652"></span><span>           </span><span class="hs-comment">-- overlaps correctly.</span><span>
</span><span id="line-653"></span><span>           </span><span class="hs-comment">-- Really we ought to only check consistency with</span><span>
</span><span id="line-654"></span><span>           </span><span class="hs-comment">-- those instances which are transitively imported</span><span>
</span><span id="line-655"></span><span>           </span><span class="hs-comment">-- by the current module, rather than every instance</span><span>
</span><span id="line-656"></span><span>           </span><span class="hs-comment">-- we've ever seen. Fixing this is part of #13102.</span><span>
</span><span id="line-657"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105239"><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105239"><span class="hs-identifier hs-var">eps</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv ExternalPackageState
forall gbl lcl. TcRnIf gbl lcl ExternalPackageState
</span><a href="GHC.Tc.Utils.Monad.html#getEps"><span class="hs-identifier hs-var">getEps</span></a></span><span>
</span><span id="line-658"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105238"><span class="annot"><span class="annottext">inst_envs :: (FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105238"><span class="hs-identifier hs-var hs-var">inst_envs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ExternalPackageState -&gt; FamInstEnv
</span><a href="GHC.Driver.Types.html#eps_fam_inst_env"><span class="hs-identifier hs-var hs-var">eps_fam_inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105239"><span class="hs-identifier hs-var">eps</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105244"><span class="hs-identifier hs-var">home_fie</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-659"></span><span>             </span><span id="local-6989586621681105236"><span class="annot"><span class="annottext">home_fie' :: FamInstEnv
</span><a href="#local-6989586621681105236"><span class="hs-identifier hs-var hs-var">home_fie'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnv -&gt; FamInst -&gt; FamInstEnv
</span><a href="GHC.Core.FamInstEnv.html#extendFamInstEnv"><span class="hs-identifier hs-var">extendFamInstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105244"><span class="hs-identifier hs-var">home_fie</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span><span>
</span><span id="line-660"></span><span>
</span><span id="line-661"></span><span>           </span><span class="hs-comment">-- Check for conflicting instance decls and injectivity violations</span><span>
</span><span id="line-662"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105234"><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105234"><span class="hs-identifier hs-var">no_errs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM () -&gt; TcRn ((), WhetherHasFamInst)
forall a. TcRn a -&gt; TcRn (a, WhetherHasFamInst)
</span><a href="GHC.Tc.Utils.Monad.html#askNoErrs"><span class="hs-identifier hs-var">askNoErrs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM () -&gt; TcRn ((), WhetherHasFamInst))
-&gt; TcM () -&gt; TcRn ((), WhetherHasFamInst)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-663"></span><span>         </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkForConflicts"><span class="hs-identifier hs-var">checkForConflicts</span></a></span><span>            </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105238"><span class="hs-identifier hs-var">inst_envs</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span><span>
</span><span id="line-664"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkForInjectivityConflicts"><span class="hs-identifier hs-var">checkForInjectivityConflicts</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105238"><span class="hs-identifier hs-var">inst_envs</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span><span>
</span><span id="line-665"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkInjectiveEquation"><span class="hs-identifier hs-var">checkInjectiveEquation</span></a></span><span>       </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span><span>
</span><span id="line-666"></span><span>            </span><span class="hs-special">}</span><span>
</span><span id="line-667"></span><span>
</span><span id="line-668"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105234"><span class="hs-identifier hs-var">no_errs</span></a></span><span> </span><span class="hs-keyword">then</span><span>
</span><span id="line-669"></span><span>            </span><span class="annot"><span class="annottext">(FamInstEnv, [FamInst])
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (FamInstEnv, [FamInst])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105236"><span class="hs-identifier hs-var">home_fie'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105242"><span class="hs-identifier hs-var">fam_inst</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; [FamInst] -&gt; [FamInst]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105243"><span class="hs-identifier hs-var">my_fis</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-670"></span><span>         </span><span class="hs-keyword">else</span><span>
</span><span id="line-671"></span><span>            </span><span class="annot"><span class="annottext">(FamInstEnv, [FamInst])
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (FamInstEnv, [FamInst])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnv
</span><a href="#local-6989586621681105244"><span class="hs-identifier hs-var">home_fie</span></a></span><span class="hs-special">,</span><span>  </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105243"><span class="hs-identifier hs-var">my_fis</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-672"></span><span>
</span><span id="line-673"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
        Checking an instance against conflicts with an instance env
*                                                                      *
************************************************************************

Check whether a single family instance conflicts with those in two instance
environments (one for the EPS and one for the HPT).
-}</span><span>
</span><span id="line-683"></span><span>
</span><span id="line-684"></span><span class="hs-comment">-- | Checks to make sure no two family instances overlap.</span><span>
</span><span id="line-685"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#checkForConflicts"><span class="hs-identifier hs-type">checkForConflicts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-686"></span><span id="checkForConflicts"><span class="annot"><span class="annottext">checkForConflicts :: (FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkForConflicts"><span class="hs-identifier hs-var hs-var">checkForConflicts</span></a></span></span><span> </span><span id="local-6989586621681105231"><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105231"><span class="hs-identifier hs-var">inst_envs</span></a></span></span><span> </span><span id="local-6989586621681105230"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105230"><span class="hs-identifier hs-var">fam_inst</span></a></span></span><span>
</span><span id="line-687"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105229"><span class="annot"><span class="annottext">conflicts :: [FamInstMatch]
</span><a href="#local-6989586621681105229"><span class="hs-identifier hs-var hs-var">conflicts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; [FamInstMatch]
</span><a href="GHC.Core.FamInstEnv.html#lookupFamInstEnvConflicts"><span class="hs-identifier hs-var">lookupFamInstEnvConflicts</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105231"><span class="hs-identifier hs-var">inst_envs</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105230"><span class="hs-identifier hs-var">fam_inst</span></a></span><span>
</span><span id="line-688"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;checkForConflicts&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcM ()) -&gt; SDoc -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-689"></span><span>         </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">[FamInst] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(FamInstMatch -&gt; FamInst) -&gt; [FamInstMatch] -&gt; [FamInst]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstMatch -&gt; FamInst
</span><a href="GHC.Core.FamInstEnv.html#fim_instance"><span class="hs-identifier hs-var hs-var">fim_instance</span></a></span><span> </span><span class="annot"><span class="annottext">[FamInstMatch]
</span><a href="#local-6989586621681105229"><span class="hs-identifier hs-var">conflicts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-690"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105230"><span class="hs-identifier hs-var">fam_inst</span></a></span><span>
</span><span id="line-691"></span><span>              </span><span class="hs-comment">-- , ppr inst_envs</span><span>
</span><span id="line-692"></span><span>         </span><span class="hs-special">]</span><span>
</span><span id="line-693"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; [FamInstMatch] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportConflictInstErr"><span class="hs-identifier hs-var">reportConflictInstErr</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105230"><span class="hs-identifier hs-var">fam_inst</span></a></span><span> </span><span class="annot"><span class="annottext">[FamInstMatch]
</span><a href="#local-6989586621681105229"><span class="hs-identifier hs-var">conflicts</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-694"></span><span>
</span><span id="line-695"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#checkForInjectivityConflicts"><span class="hs-identifier hs-type">checkForInjectivityConflicts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-696"></span><span>  </span><span class="hs-comment">-- see Note [Verifying injectivity annotation] in GHC.Core.FamInstEnv, check 1B1.</span><span>
</span><span id="line-697"></span><span id="checkForInjectivityConflicts"><span class="annot"><span class="annottext">checkForInjectivityConflicts :: (FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkForInjectivityConflicts"><span class="hs-identifier hs-var hs-var">checkForInjectivityConflicts</span></a></span></span><span> </span><span id="local-6989586621681105225"><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105225"><span class="hs-identifier hs-var">instEnvs</span></a></span></span><span> </span><span id="local-6989586621681105224"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105224"><span class="hs-identifier hs-var">famInst</span></a></span></span><span>
</span><span id="line-698"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; WhetherHasFamInst
</span><a href="GHC.Core.TyCon.html#isTypeFamilyTyCon"><span class="hs-identifier hs-var">isTypeFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105222"><span class="hs-identifier hs-var">tycon</span></a></span><span>   </span><span class="hs-comment">-- as opposed to data family tycon</span><span>
</span><span id="line-699"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#Injective"><span class="hs-identifier hs-type">Injective</span></a></span><span> </span><span id="local-6989586621681105220"><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105220"><span class="hs-identifier hs-var">inj</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Injectivity
</span><a href="GHC.Core.TyCon.html#tyConInjectivityInfo"><span class="hs-identifier hs-var">tyConInjectivityInfo</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105222"><span class="hs-identifier hs-var">tycon</span></a></span><span>
</span><span id="line-700"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105218"><span class="annot"><span class="annottext">conflicts :: [CoAxBranch]
</span><a href="#local-6989586621681105218"><span class="hs-identifier hs-var hs-var">conflicts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[WhetherHasFamInst]
-&gt; (FamInstEnv, FamInstEnv) -&gt; FamInst -&gt; [CoAxBranch]
</span><a href="GHC.Core.FamInstEnv.html#lookupFamInstEnvInjectivityConflicts"><span class="hs-identifier hs-var">lookupFamInstEnvInjectivityConflicts</span></a></span><span> </span><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105220"><span class="hs-identifier hs-var">inj</span></a></span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv)
</span><a href="#local-6989586621681105225"><span class="hs-identifier hs-var">instEnvs</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105224"><span class="hs-identifier hs-var">famInst</span></a></span><span> </span><span class="hs-keyword">in</span><span>
</span><span id="line-701"></span><span>      </span><span class="annot"><span class="annottext">TyCon -&gt; [CoAxBranch] -&gt; CoAxBranch -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportConflictingInjectivityErrs"><span class="hs-identifier hs-var">reportConflictingInjectivityErrs</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105222"><span class="hs-identifier hs-var">tycon</span></a></span><span> </span><span class="annot"><span class="annottext">[CoAxBranch]
</span><a href="#local-6989586621681105218"><span class="hs-identifier hs-var">conflicts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; CoAxBranch
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomSingleBranch"><span class="hs-identifier hs-var">coAxiomSingleBranch</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInst -&gt; CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#fi_axiom"><span class="hs-identifier hs-var hs-var">fi_axiom</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105224"><span class="hs-identifier hs-var">famInst</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-702"></span><span>
</span><span id="line-703"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-704"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-705"></span><span>
</span><span id="line-706"></span><span>    </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621681105222"><span class="annot"><span class="annottext">tycon :: TyCon
</span><a href="#local-6989586621681105222"><span class="hs-identifier hs-var hs-var">tycon</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; TyCon
</span><a href="GHC.Core.FamInstEnv.html#famInstTyCon"><span class="hs-identifier hs-var">famInstTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105224"><span class="hs-identifier hs-var">famInst</span></a></span><span>
</span><span id="line-707"></span><span>
</span><span id="line-708"></span><span class="hs-comment">-- | Check whether a new open type family equation can be added without</span><span>
</span><span id="line-709"></span><span class="hs-comment">-- violating injectivity annotation supplied by the user. Returns True when</span><span>
</span><span id="line-710"></span><span class="hs-comment">-- this is possible and False if adding this equation would violate injectivity</span><span>
</span><span id="line-711"></span><span class="hs-comment">-- annotation. This looks only at the one equation; it does not look for</span><span>
</span><span id="line-712"></span><span class="hs-comment">-- interaction between equations. Use checkForInjectivityConflicts for that.</span><span>
</span><span id="line-713"></span><span class="hs-comment">-- Does checks (2)-(4) of Note [Verifying injectivity annotation] in &quot;GHC.Core.FamInstEnv&quot;.</span><span>
</span><span id="line-714"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#checkInjectiveEquation"><span class="hs-identifier hs-type">checkInjectiveEquation</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-715"></span><span id="checkInjectiveEquation"><span class="annot"><span class="annottext">checkInjectiveEquation :: FamInst -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#checkInjectiveEquation"><span class="hs-identifier hs-var hs-var">checkInjectiveEquation</span></a></span></span><span> </span><span id="local-6989586621681105215"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105215"><span class="hs-identifier hs-var">famInst</span></a></span></span><span>
</span><span id="line-716"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; WhetherHasFamInst
</span><a href="GHC.Core.TyCon.html#isTypeFamilyTyCon"><span class="hs-identifier hs-var">isTypeFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105214"><span class="hs-identifier hs-var">tycon</span></a></span><span>
</span><span id="line-717"></span><span>    </span><span class="hs-comment">-- type family is injective in at least one argument</span><span>
</span><span id="line-718"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#Injective"><span class="hs-identifier hs-type">Injective</span></a></span><span> </span><span id="local-6989586621681105213"><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105213"><span class="hs-identifier hs-var">inj</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Injectivity
</span><a href="GHC.Core.TyCon.html#tyConInjectivityInfo"><span class="hs-identifier hs-var">tyConInjectivityInfo</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105214"><span class="hs-identifier hs-var">tycon</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-719"></span><span>    </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681105212"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681105212"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-720"></span><span>    </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105210"><span class="annot"><span class="annottext">axiom :: CoAxBranch
</span><a href="#local-6989586621681105210"><span class="hs-identifier hs-var hs-var">axiom</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; CoAxBranch
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomSingleBranch"><span class="hs-identifier hs-var">coAxiomSingleBranch</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105209"><span class="hs-identifier hs-var">fi_ax</span></a></span><span>
</span><span id="line-721"></span><span>          </span><span class="hs-comment">-- see Note [Verifying injectivity annotation] in GHC.Core.FamInstEnv</span><span>
</span><span id="line-722"></span><span>    </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; CoAxiom Unbranched
-&gt; CoAxBranch
-&gt; [WhetherHasFamInst]
-&gt; TcM ()
forall (br :: BranchFlag).
DynFlags
-&gt; CoAxiom br -&gt; CoAxBranch -&gt; [WhetherHasFamInst] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportInjectivityErrors"><span class="hs-identifier hs-var">reportInjectivityErrors</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681105212"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105209"><span class="hs-identifier hs-var">fi_ax</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105210"><span class="hs-identifier hs-var">axiom</span></a></span><span> </span><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105213"><span class="hs-identifier hs-var">inj</span></a></span><span>
</span><span id="line-723"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-724"></span><span>
</span><span id="line-725"></span><span>    </span><span class="hs-comment">-- if there was no injectivity annotation or tycon does not represent a</span><span>
</span><span id="line-726"></span><span>    </span><span class="hs-comment">-- type family we report no conflicts</span><span>
</span><span id="line-727"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-728"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-729"></span><span>
</span><span id="line-730"></span><span>    </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621681105214"><span class="annot"><span class="annottext">tycon :: TyCon
</span><a href="#local-6989586621681105214"><span class="hs-identifier hs-var hs-var">tycon</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; TyCon
</span><a href="GHC.Core.FamInstEnv.html#famInstTyCon"><span class="hs-identifier hs-var">famInstTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105215"><span class="hs-identifier hs-var">famInst</span></a></span><span>
</span><span id="line-731"></span><span>          </span><span id="local-6989586621681105209"><span class="annot"><span class="annottext">fi_ax :: CoAxiom Unbranched
</span><a href="#local-6989586621681105209"><span class="hs-identifier hs-var hs-var">fi_ax</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#fi_axiom"><span class="hs-identifier hs-var hs-var">fi_axiom</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105215"><span class="hs-identifier hs-var">famInst</span></a></span><span>
</span><span id="line-732"></span><span>
</span><span id="line-733"></span><span class="hs-comment">-- | Report a list of injectivity errors together with their source locations.</span><span>
</span><span id="line-734"></span><span class="hs-comment">-- Looks only at one equation; does not look for conflicts *among* equations.</span><span>
</span><span id="line-735"></span><span id="local-6989586621681105593"><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportInjectivityErrors"><span class="hs-identifier hs-type">reportInjectivityErrors</span></a></span><span>
</span><span id="line-736"></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-737"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxiom"><span class="hs-identifier hs-type">CoAxiom</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681105593"><span class="hs-identifier hs-type">br</span></a></span><span>   </span><span class="hs-comment">-- ^ Type family for which we generate errors</span><span>
</span><span id="line-738"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span>   </span><span class="hs-comment">-- ^ Currently checked equation (represented by axiom)</span><span>
</span><span id="line-739"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">]</span><span>       </span><span class="hs-comment">-- ^ Injectivity annotation</span><span>
</span><span id="line-740"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-741"></span><span id="reportInjectivityErrors"><span class="annot"><span class="annottext">reportInjectivityErrors :: forall (br :: BranchFlag).
DynFlags
-&gt; CoAxiom br -&gt; CoAxBranch -&gt; [WhetherHasFamInst] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportInjectivityErrors"><span class="hs-identifier hs-var hs-var">reportInjectivityErrors</span></a></span></span><span> </span><span id="local-6989586621681105198"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681105198"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621681105197"><span class="annot"><span class="annottext">CoAxiom br
</span><a href="#local-6989586621681105197"><span class="hs-identifier hs-var">fi_ax</span></a></span></span><span> </span><span id="local-6989586621681105196"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105196"><span class="hs-identifier hs-var">axiom</span></a></span></span><span> </span><span id="local-6989586621681105195"><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105195"><span class="hs-identifier hs-var">inj</span></a></span></span><span>
</span><span id="line-742"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">any</span><span> </span><span class="hs-identifier">id</span><span> </span><span class="hs-identifier">inj</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">text</span><span> </span><span class="hs-string">&quot;No injective type variables&quot;</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-743"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105191"><span class="annot"><span class="annottext">lhs :: [Type]
</span><a href="#local-6989586621681105191"><span class="hs-identifier hs-var hs-var">lhs</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; [Type]
</span><a href="GHC.Core.Coercion.Axiom.html#coAxBranchLHS"><span class="hs-identifier hs-var">coAxBranchLHS</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105196"><span class="hs-identifier hs-var">axiom</span></a></span><span>
</span><span id="line-744"></span><span>           </span><span id="local-6989586621681105189"><span class="annot"><span class="annottext">rhs :: Type
</span><a href="#local-6989586621681105189"><span class="hs-identifier hs-var hs-var">rhs</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; Type
</span><a href="GHC.Core.Coercion.Axiom.html#coAxBranchRHS"><span class="hs-identifier hs-var">coAxBranchRHS</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105196"><span class="hs-identifier hs-var">axiom</span></a></span><span>
</span><span id="line-745"></span><span>           </span><span id="local-6989586621681105187"><span class="annot"><span class="annottext">fam_tc :: TyCon
</span><a href="#local-6989586621681105187"><span class="hs-identifier hs-var hs-var">fam_tc</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxiom br -&gt; TyCon
forall (br :: BranchFlag). CoAxiom br -&gt; TyCon
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomTyCon"><span class="hs-identifier hs-var">coAxiomTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom br
</span><a href="#local-6989586621681105197"><span class="hs-identifier hs-var">fi_ax</span></a></span><span>
</span><span id="line-746"></span><span>           </span><span class="hs-special">(</span><span id="local-6989586621681105185"><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105185"><span class="hs-identifier hs-var">unused_inj_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105184"><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105184"><span class="hs-identifier hs-var">unused_vis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105183"><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105183"><span class="hs-identifier hs-var">undec_inst_flag</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-747"></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; TyCon
-&gt; [Type]
-&gt; Type
-&gt; (TyVarSet, WhetherHasFamInst, WhetherHasFamInst)
</span><a href="GHC.Tc.Instance.Family.html#unusedInjTvsInRHS"><span class="hs-identifier hs-var">unusedInjTvsInRHS</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681105198"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105187"><span class="hs-identifier hs-var">fam_tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105191"><span class="hs-identifier hs-var">lhs</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105189"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-748"></span><span>           </span><span id="local-6989586621681105181"><span class="annot"><span class="annottext">inj_tvs_unused :: WhetherHasFamInst
</span><a href="#local-6989586621681105181"><span class="hs-identifier hs-var hs-var">inj_tvs_unused</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">(WhetherHasFamInst -&gt; WhetherHasFamInst)
-&gt; WhetherHasFamInst -&gt; WhetherHasFamInst
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet -&gt; WhetherHasFamInst
</span><a href="GHC.Types.Var.Set.html#isEmptyVarSet"><span class="hs-identifier hs-var">isEmptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105185"><span class="hs-identifier hs-var">unused_inj_tvs</span></a></span><span>
</span><span id="line-749"></span><span>           </span><span id="local-6989586621681105179"><span class="annot"><span class="annottext">tf_headed :: WhetherHasFamInst
</span><a href="#local-6989586621681105179"><span class="hs-identifier hs-var hs-var">tf_headed</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; WhetherHasFamInst
</span><a href="GHC.Tc.Instance.Family.html#isTFHeaded"><span class="hs-identifier hs-var">isTFHeaded</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105189"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-750"></span><span>           </span><span id="local-6989586621681105177"><span class="annot"><span class="annottext">bare_variables :: [Type]
</span><a href="#local-6989586621681105177"><span class="hs-identifier hs-var hs-var">bare_variables</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; Type -&gt; [Type]
</span><a href="GHC.Tc.Instance.Family.html#bareTvInRHSViolated"><span class="hs-identifier hs-var">bareTvInRHSViolated</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105191"><span class="hs-identifier hs-var">lhs</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105189"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-751"></span><span>           </span><span id="local-6989586621681105175"><span class="annot"><span class="annottext">wrong_bare_rhs :: WhetherHasFamInst
</span><a href="#local-6989586621681105175"><span class="hs-identifier hs-var hs-var">wrong_bare_rhs</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">(WhetherHasFamInst -&gt; WhetherHasFamInst)
-&gt; WhetherHasFamInst -&gt; WhetherHasFamInst
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; WhetherHasFamInst
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; WhetherHasFamInst
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105177"><span class="hs-identifier hs-var">bare_variables</span></a></span><span>
</span><span id="line-752"></span><span>
</span><span id="line-753"></span><span>       </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; TcM () -&gt; TcM ()
forall (f :: * -&gt; *).
Applicative f =&gt;
WhetherHasFamInst -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105181"><span class="hs-identifier hs-var">inj_tvs_unused</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM () -&gt; TcM ()) -&gt; TcM () -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
-&gt; TyVarSet
-&gt; WhetherHasFamInst
-&gt; WhetherHasFamInst
-&gt; CoAxBranch
-&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportUnusedInjectiveVarsErr"><span class="hs-identifier hs-var">reportUnusedInjectiveVarsErr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105187"><span class="hs-identifier hs-var">fam_tc</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105185"><span class="hs-identifier hs-var">unused_inj_tvs</span></a></span><span>
</span><span id="line-754"></span><span>                                                          </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105184"><span class="hs-identifier hs-var">unused_vis</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105183"><span class="hs-identifier hs-var">undec_inst_flag</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105196"><span class="hs-identifier hs-var">axiom</span></a></span><span>
</span><span id="line-755"></span><span>       </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; TcM () -&gt; TcM ()
forall (f :: * -&gt; *).
Applicative f =&gt;
WhetherHasFamInst -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105179"><span class="hs-identifier hs-var">tf_headed</span></a></span><span>      </span><span class="annot"><span class="annottext">(TcM () -&gt; TcM ()) -&gt; TcM () -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; CoAxBranch -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportTfHeadedErr"><span class="hs-identifier hs-var">reportTfHeadedErr</span></a></span><span>            </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105187"><span class="hs-identifier hs-var">fam_tc</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105196"><span class="hs-identifier hs-var">axiom</span></a></span><span>
</span><span id="line-756"></span><span>       </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; TcM () -&gt; TcM ()
forall (f :: * -&gt; *).
Applicative f =&gt;
WhetherHasFamInst -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105175"><span class="hs-identifier hs-var">wrong_bare_rhs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM () -&gt; TcM ()) -&gt; TcM () -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [Type] -&gt; CoAxBranch -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportBareVariableInRHSErr"><span class="hs-identifier hs-var">reportBareVariableInRHSErr</span></a></span><span>   </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105187"><span class="hs-identifier hs-var">fam_tc</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105177"><span class="hs-identifier hs-var">bare_variables</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105196"><span class="hs-identifier hs-var">axiom</span></a></span><span>
</span><span id="line-757"></span><span>
</span><span id="line-758"></span><span class="hs-comment">-- | Is type headed by a type family application?</span><span>
</span><span id="line-759"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#isTFHeaded"><span class="hs-identifier hs-type">isTFHeaded</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-760"></span><span class="hs-comment">-- See Note [Verifying injectivity annotation], case 3.</span><span>
</span><span id="line-761"></span><span id="isTFHeaded"><span class="annot"><span class="annottext">isTFHeaded :: Type -&gt; WhetherHasFamInst
</span><a href="GHC.Tc.Instance.Family.html#isTFHeaded"><span class="hs-identifier hs-var hs-var">isTFHeaded</span></a></span></span><span> </span><span id="local-6989586621681105170"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105170"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681105169"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105169"><span class="hs-identifier hs-var">ty'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Maybe Type
</span><a href="GHC.Core.Type.html#coreView"><span class="hs-identifier hs-var">coreView</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105170"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-762"></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; WhetherHasFamInst
</span><a href="GHC.Tc.Instance.Family.html#isTFHeaded"><span class="hs-identifier hs-var">isTFHeaded</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105169"><span class="hs-identifier hs-var">ty'</span></a></span><span>
</span><span id="line-763"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#isTFHeaded"><span class="hs-identifier hs-var">isTFHeaded</span></a></span><span> </span><span id="local-6989586621681105167"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105167"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyConApp"><span class="hs-identifier hs-type">TyConApp</span></a></span><span> </span><span id="local-6989586621681105165"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105165"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681105164"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105164"><span class="hs-identifier hs-var">args</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105167"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-764"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; WhetherHasFamInst
</span><a href="GHC.Core.TyCon.html#isTypeFamilyTyCon"><span class="hs-identifier hs-var">isTypeFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105165"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-765"></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105164"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; Int -&gt; WhetherHasFamInst
forall a. [a] -&gt; Int -&gt; WhetherHasFamInst
</span><a href="GHC.Utils.Misc.html#lengthIs"><span class="hs-operator hs-var">`lengthIs`</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Int
</span><a href="GHC.Core.TyCon.html#tyConArity"><span class="hs-identifier hs-var hs-var">tyConArity</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105165"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-766"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#isTFHeaded"><span class="hs-identifier hs-var">isTFHeaded</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-767"></span><span>
</span><span id="line-768"></span><span>
</span><span id="line-769"></span><span class="hs-comment">-- | If a RHS is a bare type variable return a set of LHS patterns that are not</span><span>
</span><span id="line-770"></span><span class="hs-comment">-- bare type variables.</span><span>
</span><span id="line-771"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#bareTvInRHSViolated"><span class="hs-identifier hs-type">bareTvInRHSViolated</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-772"></span><span class="hs-comment">-- See Note [Verifying injectivity annotation], case 2.</span><span>
</span><span id="line-773"></span><span id="bareTvInRHSViolated"><span class="annot"><span class="annottext">bareTvInRHSViolated :: [Type] -&gt; Type -&gt; [Type]
</span><a href="GHC.Tc.Instance.Family.html#bareTvInRHSViolated"><span class="hs-identifier hs-var hs-var">bareTvInRHSViolated</span></a></span></span><span> </span><span id="local-6989586621681105161"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105161"><span class="hs-identifier hs-var">pats</span></a></span></span><span> </span><span id="local-6989586621681105160"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105160"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Type -&gt; WhetherHasFamInst
</span><a href="GHC.Core.Type.html#isTyVarTy"><span class="hs-identifier hs-var">isTyVarTy</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105160"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-774"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Type -&gt; WhetherHasFamInst) -&gt; [Type] -&gt; [Type]
forall a. (a -&gt; WhetherHasFamInst) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">(WhetherHasFamInst -&gt; WhetherHasFamInst)
-&gt; (Type -&gt; WhetherHasFamInst) -&gt; Type -&gt; WhetherHasFamInst
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; WhetherHasFamInst
</span><a href="GHC.Core.Type.html#isTyVarTy"><span class="hs-identifier hs-var">isTyVarTy</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105161"><span class="hs-identifier hs-var">pats</span></a></span><span>
</span><span id="line-775"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#bareTvInRHSViolated"><span class="hs-identifier hs-var">bareTvInRHSViolated</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-776"></span><span>
</span><span id="line-777"></span><span class="hs-comment">------------------------------------------------------------------</span><span>
</span><span id="line-778"></span><span class="hs-comment">-- Checking for the coverage condition for injective type families</span><span>
</span><span id="line-779"></span><span class="hs-comment">------------------------------------------------------------------</span><span>
</span><span id="line-780"></span><span>
</span><span id="line-781"></span><span class="hs-comment">{-
Note [Coverage condition for injective type families]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Injective Type Families paper describes how we can tell whether
or not a type family equation upholds the injectivity condition.
Briefly, consider the following:

  type family F a b = r | r -&gt; a      -- NB: b is not injective

  type instance F ty1 ty2 = ty3

We need to make sure that all variables mentioned in ty1 are mentioned in ty3
-- that's how we know that knowing ty3 determines ty1. But they can't be
mentioned just anywhere in ty3: they must be in *injective* positions in ty3.
For example:

  type instance F a Int = Maybe (G a)

This is no good, if G is not injective. However, if G is indeed injective,
then this would appear to meet our needs. There is a trap here, though: while
knowing G a does indeed determine a, trying to compute a from G a might not
terminate. This is precisely the same problem that we have with functional
dependencies and their liberal coverage condition. Here is the test case:

  type family G a = r | r -&gt; a
  type instance G [a] = [G a]
  [W] G alpha ~ [alpha]

We see that the equation given applies, because G alpha equals a list. So we
learn that alpha must be [beta] for some beta. We then have

  [W] G [beta] ~ [[beta]]

This can reduce to

  [W] [G beta] ~ [[beta]]

which then decomposes to

  [W] G beta ~ [beta]

right where we started. The equation G [a] = [G a] thus is dangerous: while
it does not violate the injectivity assumption, it might throw us into a loop,
with a particularly dastardly Wanted.

We thus do what functional dependencies do: require -XUndecidableInstances to
accept this.

Checking the coverage condition is not terribly hard, but we also want to produce
a nice error message. A nice error message has at least two properties:

1. If any of the variables involved are invisible or are used in an invisible context,
we want to print invisible arguments (as -fprint-explicit-kinds does).

2. If we fail to accept the equation because we're worried about non-termination,
we want to suggest UndecidableInstances.

To gather the right information, we can talk about the *usage* of a variable. Every
variable is used either visibly or invisibly, and it is either not used at all,
in a context where acceptance requires UndecidableInstances, or in a context that
does not require UndecidableInstances. If a variable is used both visibly and
invisibly, then we want to remember the fact that it was used invisibly: printing
out invisibles will be helpful for the user to understand what is going on.
If a variable is used where we need -XUndecidableInstances and where we don't,
we can similarly just remember the latter.

We thus define Visibility and NeedsUndecInstFlag below. These enumerations are
*ordered*, and we used their Ord instances. We then define VarUsage, which is just a pair
of a Visibility and a NeedsUndecInstFlag. (The visibility is irrelevant when a
variable is NotPresent, but this extra slack in the representation causes no
harm.) We finally define VarUsages as a mapping from variables to VarUsage.
Its Monoid instance combines two maps, using the Semigroup instance of VarUsage
to combine elements that are represented in both maps. In this way, we can
compositionally analyze types (and portions thereof).

To do the injectivity check:

1. We build VarUsages that represent the LHS (rather, the portion of the LHS
that is flagged as injective); each usage on the LHS is NotPresent, because we
have not yet looked at the RHS.

2. We also build a VarUsage for the RHS, done by injTyVarUsages.

3. We then combine these maps. Now, every variable in the injective components of the LHS
will be mapped to its correct usage (either NotPresent or perhaps needing
-XUndecidableInstances in order to be seen as injective).

4. We look up each var used in an injective argument on the LHS in
the map, making a list of tvs that should be determined by the RHS
but aren't.

5. We then return the set of bad variables, whether any of the bad
ones were used invisibly, and whether any bad ones need -XUndecidableInstances.
If -XUndecidableInstances is enabled, than a var that needs the flag
won't be bad, so it won't appear in this list.

6. We use all this information to produce a nice error message, (a) switching
on -fprint-explicit-kinds if appropriate and (b) telling the user about
-XUndecidableInstances if appropriate.

-}</span><span>
</span><span id="line-882"></span><span>
</span><span id="line-883"></span><span class="hs-comment">-- | Return the set of type variables that a type family equation is</span><span>
</span><span id="line-884"></span><span class="hs-comment">-- expected to be injective in but is not. Suppose we have @type family</span><span>
</span><span id="line-885"></span><span class="hs-comment">-- F a b = r | r -&gt; a@. Then any variables that appear free in the first</span><span>
</span><span id="line-886"></span><span class="hs-comment">-- argument to F in an equation must be fixed by that equation's RHS.</span><span>
</span><span id="line-887"></span><span class="hs-comment">-- This function returns all such variables that are not indeed fixed.</span><span>
</span><span id="line-888"></span><span class="hs-comment">-- It also returns whether any of these variables appear invisibly</span><span>
</span><span id="line-889"></span><span class="hs-comment">-- and whether -XUndecidableInstances would help.</span><span>
</span><span id="line-890"></span><span class="hs-comment">-- See Note [Coverage condition for injective type families].</span><span>
</span><span id="line-891"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#unusedInjTvsInRHS"><span class="hs-identifier hs-type">unusedInjTvsInRHS</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-892"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>  </span><span class="hs-comment">-- type family</span><span>
</span><span id="line-893"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- LHS arguments</span><span>
</span><span id="line-894"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>   </span><span class="hs-comment">-- the RHS</span><span>
</span><span id="line-895"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#TyVarSet"><span class="hs-identifier hs-type">TyVarSet</span></a></span><span>
</span><span id="line-896"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>   </span><span class="hs-comment">-- True &lt;=&gt; one or more variable is used invisibly</span><span>
</span><span id="line-897"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- True &lt;=&gt; suggest -XUndecidableInstances</span><span>
</span><span id="line-898"></span><span class="hs-comment">-- See Note [Verifying injectivity annotation] in GHC.Core.FamInstEnv.</span><span>
</span><span id="line-899"></span><span class="hs-comment">-- This function implements check (4) described there, further</span><span>
</span><span id="line-900"></span><span class="hs-comment">-- described in Note [Coverage condition for injective type families].</span><span>
</span><span id="line-901"></span><span class="hs-comment">-- In theory (and modulo the -XUndecidableInstances wrinkle),</span><span>
</span><span id="line-902"></span><span class="hs-comment">-- instead of implementing this whole check in this way, we could</span><span>
</span><span id="line-903"></span><span class="hs-comment">-- attempt to unify equation with itself.  We would reject exactly the same</span><span>
</span><span id="line-904"></span><span class="hs-comment">-- equations but this method gives us more precise error messages by returning</span><span>
</span><span id="line-905"></span><span class="hs-comment">-- precise names of variables that are not mentioned in the RHS.</span><span>
</span><span id="line-906"></span><span id="unusedInjTvsInRHS"><span class="annot"><span class="annottext">unusedInjTvsInRHS :: DynFlags
-&gt; TyCon
-&gt; [Type]
-&gt; Type
-&gt; (TyVarSet, WhetherHasFamInst, WhetherHasFamInst)
</span><a href="GHC.Tc.Instance.Family.html#unusedInjTvsInRHS"><span class="hs-identifier hs-var hs-var">unusedInjTvsInRHS</span></a></span></span><span> </span><span id="local-6989586621681105158"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681105158"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621681105157"><span class="annot"><span class="annottext">tycon :: TyCon
</span><a href="#local-6989586621681105157"><span class="hs-identifier hs-var">tycon</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Injectivity
</span><a href="GHC.Core.TyCon.html#tyConInjectivityInfo"><span class="hs-identifier hs-var">tyConInjectivityInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#Injective"><span class="hs-identifier hs-type">Injective</span></a></span><span> </span><span id="local-6989586621681105156"><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105156"><span class="hs-identifier hs-var">inj_list</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681105155"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105155"><span class="hs-identifier hs-var">lhs</span></a></span></span><span> </span><span id="local-6989586621681105154"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105154"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-907"></span><span>  </span><span class="hs-comment">-- Note [Coverage condition for injective type families], step 5</span><span>
</span><span id="line-908"></span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105153"><span class="hs-identifier hs-var">bad_vars</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105152"><span class="hs-identifier hs-var">any_invisible</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105151"><span class="hs-identifier hs-var">suggest_undec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-909"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-910"></span><span>      </span><span id="local-6989586621681105150"><span class="annot"><span class="annottext">undec_inst :: WhetherHasFamInst
</span><a href="#local-6989586621681105150"><span class="hs-identifier hs-var hs-var">undec_inst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Extension -&gt; DynFlags -&gt; WhetherHasFamInst
</span><a href="GHC.Driver.Session.html#xopt"><span class="hs-identifier hs-var">xopt</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#UndecidableInstances"><span class="hs-identifier hs-var">LangExt.UndecidableInstances</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681105158"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-911"></span><span>
</span><span id="line-912"></span><span>      </span><span id="local-6989586621681105147"><span class="annot"><span class="annottext">inj_lhs :: [Type]
</span><a href="#local-6989586621681105147"><span class="hs-identifier hs-var hs-var">inj_lhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[WhetherHasFamInst] -&gt; [Type] -&gt; [Type]
forall a. [WhetherHasFamInst] -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#filterByList"><span class="hs-identifier hs-var">filterByList</span></a></span><span> </span><span class="annot"><span class="annottext">[WhetherHasFamInst]
</span><a href="#local-6989586621681105156"><span class="hs-identifier hs-var">inj_list</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105155"><span class="hs-identifier hs-var">lhs</span></a></span><span>
</span><span id="line-913"></span><span>      </span><span id="local-6989586621681105145"><span class="annot"><span class="annottext">lhs_vars :: TyVarSet
</span><a href="#local-6989586621681105145"><span class="hs-identifier hs-var hs-var">lhs_vars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; TyVarSet
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfTypes"><span class="hs-identifier hs-var">tyCoVarsOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105147"><span class="hs-identifier hs-var">inj_lhs</span></a></span><span>
</span><span id="line-914"></span><span>
</span><span id="line-915"></span><span>      </span><span id="local-6989586621681105143"><span class="annot"><span class="annottext">rhs_inj_vars :: TyVarSet
</span><a href="#local-6989586621681105143"><span class="hs-identifier hs-var hs-var">rhs_inj_vars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FV -&gt; TyVarSet
</span><a href="GHC.Utils.FV.html#fvVarSet"><span class="hs-identifier hs-var">fvVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(FV -&gt; TyVarSet) -&gt; FV -&gt; TyVarSet
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; Type -&gt; FV
</span><a href="GHC.Core.TyCo.FVs.html#injectiveVarsOfType"><span class="hs-identifier hs-var">injectiveVarsOfType</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105150"><span class="hs-identifier hs-var">undec_inst</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105154"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-916"></span><span>
</span><span id="line-917"></span><span>      </span><span id="local-6989586621681105153"><span class="annot"><span class="annottext">bad_vars :: TyVarSet
</span><a href="#local-6989586621681105153"><span class="hs-identifier hs-var hs-var">bad_vars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105145"><span class="hs-identifier hs-var">lhs_vars</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet -&gt; TyVarSet -&gt; TyVarSet
</span><a href="GHC.Types.Var.Set.html#minusVarSet"><span class="hs-operator hs-var">`minusVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105143"><span class="hs-identifier hs-var">rhs_inj_vars</span></a></span><span>
</span><span id="line-918"></span><span>
</span><span id="line-919"></span><span>      </span><span id="local-6989586621681105139"><span class="annot"><span class="annottext">any_bad :: WhetherHasFamInst
</span><a href="#local-6989586621681105139"><span class="hs-identifier hs-var hs-var">any_bad</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">(WhetherHasFamInst -&gt; WhetherHasFamInst)
-&gt; WhetherHasFamInst -&gt; WhetherHasFamInst
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet -&gt; WhetherHasFamInst
</span><a href="GHC.Types.Var.Set.html#isEmptyVarSet"><span class="hs-identifier hs-var">isEmptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105153"><span class="hs-identifier hs-var">bad_vars</span></a></span><span>
</span><span id="line-920"></span><span>
</span><span id="line-921"></span><span>      </span><span id="local-6989586621681105138"><span class="annot"><span class="annottext">invis_vars :: TyVarSet
</span><a href="#local-6989586621681105138"><span class="hs-identifier hs-var hs-var">invis_vars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FV -&gt; TyVarSet
</span><a href="GHC.Utils.FV.html#fvVarSet"><span class="hs-identifier hs-var">fvVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(FV -&gt; TyVarSet) -&gt; FV -&gt; TyVarSet
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; FV
</span><a href="GHC.Core.TyCo.FVs.html#invisibleVarsOfTypes"><span class="hs-identifier hs-var">invisibleVarsOfTypes</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TyCon -&gt; [Type] -&gt; Type
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105157"><span class="hs-identifier hs-var">tycon</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105155"><span class="hs-identifier hs-var">lhs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105154"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-922"></span><span>
</span><span id="line-923"></span><span>      </span><span id="local-6989586621681105152"><span class="annot"><span class="annottext">any_invisible :: WhetherHasFamInst
</span><a href="#local-6989586621681105152"><span class="hs-identifier hs-var hs-var">any_invisible</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105139"><span class="hs-identifier hs-var">any_bad</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105153"><span class="hs-identifier hs-var">bad_vars</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet -&gt; TyVarSet -&gt; WhetherHasFamInst
</span><a href="GHC.Types.Var.Set.html#intersectsVarSet"><span class="hs-operator hs-var">`intersectsVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105138"><span class="hs-identifier hs-var">invis_vars</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-924"></span><span>      </span><span id="local-6989586621681105151"><span class="annot"><span class="annottext">suggest_undec :: WhetherHasFamInst
</span><a href="#local-6989586621681105151"><span class="hs-identifier hs-var hs-var">suggest_undec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105139"><span class="hs-identifier hs-var">any_bad</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span>
</span><span id="line-925"></span><span>                      </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105150"><span class="hs-identifier hs-var">undec_inst</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; WhetherHasFamInst -&gt; WhetherHasFamInst
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span>
</span><span id="line-926"></span><span>                      </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105145"><span class="hs-identifier hs-var">lhs_vars</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet -&gt; TyVarSet -&gt; WhetherHasFamInst
</span><a href="GHC.Types.Var.Set.html#subVarSet"><span class="hs-operator hs-var">`subVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">FV -&gt; TyVarSet
</span><a href="GHC.Utils.FV.html#fvVarSet"><span class="hs-identifier hs-var">fvVarSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; Type -&gt; FV
</span><a href="GHC.Core.TyCo.FVs.html#injectiveVarsOfType"><span class="hs-identifier hs-var">injectiveVarsOfType</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621681105154"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-927"></span><span>
</span><span id="line-928"></span><span class="hs-comment">-- When the type family is not injective in any arguments</span><span>
</span><span id="line-929"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#unusedInjTvsInRHS"><span class="hs-identifier hs-var">unusedInjTvsInRHS</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVarSet
</span><a href="GHC.Types.Var.Set.html#emptyVarSet"><span class="hs-identifier hs-var">emptyVarSet</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span>
</span><span id="line-930"></span><span>
</span><span id="line-931"></span><span class="hs-comment">---------------------------------------</span><span>
</span><span id="line-932"></span><span class="hs-comment">-- Producing injectivity error messages</span><span>
</span><span id="line-933"></span><span class="hs-comment">---------------------------------------</span><span>
</span><span id="line-934"></span><span>
</span><span id="line-935"></span><span class="hs-comment">-- | Report error message for a pair of equations violating an injectivity</span><span>
</span><span id="line-936"></span><span class="hs-comment">-- annotation. No error message if there are no branches.</span><span>
</span><span id="line-937"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportConflictingInjectivityErrs"><span class="hs-identifier hs-type">reportConflictingInjectivityErrs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-938"></span><span id="reportConflictingInjectivityErrs"><span class="annot"><span class="annottext">reportConflictingInjectivityErrs :: TyCon -&gt; [CoAxBranch] -&gt; CoAxBranch -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportConflictingInjectivityErrs"><span class="hs-identifier hs-var hs-var">reportConflictingInjectivityErrs</span></a></span></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-939"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportConflictingInjectivityErrs"><span class="hs-identifier hs-var">reportConflictingInjectivityErrs</span></a></span><span> </span><span id="local-6989586621681105133"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105133"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105132"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105132"><span class="hs-identifier hs-var">confEqn1</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[CoAxBranch]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681105131"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105131"><span class="hs-identifier hs-var">tyfamEqn</span></a></span></span><span>
</span><span id="line-940"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(SrcSpan, SDoc)] -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#addErrs"><span class="hs-identifier hs-var">addErrs</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc -&gt; NonEmpty CoAxBranch -&gt; (SrcSpan, SDoc)
</span><a href="GHC.Tc.Instance.Family.html#buildInjectivityError"><span class="hs-identifier hs-var">buildInjectivityError</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105133"><span class="hs-identifier hs-var">fam_tc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105128"><span class="hs-identifier hs-var">herald</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105132"><span class="hs-identifier hs-var">confEqn1</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; [CoAxBranch] -&gt; NonEmpty CoAxBranch
forall a. a -&gt; [a] -&gt; NonEmpty a
</span><a href="../../base/src/GHC.Base.html#%3A%7C"><span class="hs-operator hs-var">:|</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105131"><span class="hs-identifier hs-var">tyfamEqn</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-941"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-942"></span><span>    </span><span id="local-6989586621681105128"><span class="annot"><span class="annottext">herald :: SDoc
</span><a href="#local-6989586621681105128"><span class="hs-identifier hs-var hs-var">herald</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Type family equation right-hand sides overlap; this violates&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-943"></span><span>             </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;the family's injectivity annotation:&quot;</span></span><span>
</span><span id="line-944"></span><span>
</span><span id="line-945"></span><span class="hs-comment">-- | Injectivity error herald common to all injectivity errors.</span><span>
</span><span id="line-946"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#injectivityErrorHerald"><span class="hs-identifier hs-type">injectivityErrorHerald</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-947"></span><span id="injectivityErrorHerald"><span class="annot"><span class="annottext">injectivityErrorHerald :: SDoc
</span><a href="GHC.Tc.Instance.Family.html#injectivityErrorHerald"><span class="hs-identifier hs-var hs-var">injectivityErrorHerald</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-948"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Type family equation violates the family's injectivity annotation.&quot;</span></span><span>
</span><span id="line-949"></span><span>
</span><span id="line-950"></span><span>
</span><span id="line-951"></span><span class="hs-comment">-- | Report error message for equation with injective type variables unused in</span><span>
</span><span id="line-952"></span><span class="hs-comment">-- the RHS. Note [Coverage condition for injective type families], step 6</span><span>
</span><span id="line-953"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportUnusedInjectiveVarsErr"><span class="hs-identifier hs-type">reportUnusedInjectiveVarsErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>
</span><span id="line-954"></span><span>                             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#TyVarSet"><span class="hs-identifier hs-type">TyVarSet</span></a></span><span>
</span><span id="line-955"></span><span>                             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>   </span><span class="hs-comment">-- True &lt;=&gt; print invisible arguments</span><span>
</span><span id="line-956"></span><span>                             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>   </span><span class="hs-comment">-- True &lt;=&gt; suggest -XUndecidableInstances</span><span>
</span><span id="line-957"></span><span>                             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span>
</span><span id="line-958"></span><span>                             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-959"></span><span id="reportUnusedInjectiveVarsErr"><span class="annot"><span class="annottext">reportUnusedInjectiveVarsErr :: TyCon
-&gt; TyVarSet
-&gt; WhetherHasFamInst
-&gt; WhetherHasFamInst
-&gt; CoAxBranch
-&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportUnusedInjectiveVarsErr"><span class="hs-identifier hs-var hs-var">reportUnusedInjectiveVarsErr</span></a></span></span><span> </span><span id="local-6989586621681105125"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105125"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span> </span><span id="local-6989586621681105124"><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105124"><span class="hs-identifier hs-var">tvs</span></a></span></span><span> </span><span id="local-6989586621681105123"><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105123"><span class="hs-identifier hs-var">has_kinds</span></a></span></span><span> </span><span id="local-6989586621681105122"><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105122"><span class="hs-identifier hs-var">undec_inst</span></a></span></span><span> </span><span id="local-6989586621681105121"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105121"><span class="hs-identifier hs-var">tyfamEqn</span></a></span></span><span>
</span><span id="line-960"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105120"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681105120"><span class="hs-identifier hs-var">loc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681105119"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105119"><span class="hs-identifier hs-var">doc</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc -&gt; NonEmpty CoAxBranch -&gt; (SrcSpan, SDoc)
</span><a href="GHC.Tc.Instance.Family.html#buildInjectivityError"><span class="hs-identifier hs-var">buildInjectivityError</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105125"><span class="hs-identifier hs-var">fam_tc</span></a></span><span>
</span><span id="line-961"></span><span>                                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Tc.Instance.Family.html#injectivityErrorHerald"><span class="hs-identifier hs-var">injectivityErrorHerald</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-962"></span><span>                                   </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105118"><span class="hs-identifier hs-var">herald</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-963"></span><span>                                   </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;In the type family equation:&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-964"></span><span>                                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105121"><span class="hs-identifier hs-var">tyfamEqn</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; [CoAxBranch] -&gt; NonEmpty CoAxBranch
forall a. a -&gt; [a] -&gt; NonEmpty a
</span><a href="../../base/src/GHC.Base.html#%3A%7C"><span class="hs-operator hs-var">:|</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-965"></span><span>    </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">SrcSpan -&gt; SDoc -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#addErrAt"><span class="hs-identifier hs-var">addErrAt</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681105120"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WhetherHasFamInst -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprWithExplicitKindsWhen"><span class="hs-identifier hs-var">pprWithExplicitKindsWhen</span></a></span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105123"><span class="hs-identifier hs-var">has_kinds</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105119"><span class="hs-identifier hs-var">doc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-966"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-967"></span><span>      </span><span id="local-6989586621681105118"><span class="annot"><span class="annottext">herald :: SDoc
</span><a href="#local-6989586621681105118"><span class="hs-identifier hs-var hs-var">herald</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105115"><span class="hs-identifier hs-var">what</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;variable&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span>
</span><span id="line-968"></span><span>                  </span><span class="annot"><span class="annottext">TyVarSet -&gt; SDoc
</span><a href="GHC.Types.Var.Set.html#pluralVarSet"><span class="hs-identifier hs-var">pluralVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105124"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet -&gt; ([TyCoVar] -&gt; SDoc) -&gt; SDoc
</span><a href="GHC.Types.Var.Set.html#pprVarSet"><span class="hs-identifier hs-var">pprVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarSet
</span><a href="#local-6989586621681105124"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyCoVar] -&gt; SDoc
forall a. Outputable a =&gt; [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#pprQuotedList"><span class="hs-identifier hs-var">pprQuotedList</span></a></span><span> </span><span class="annot"><span class="annottext">([TyCoVar] -&gt; SDoc)
-&gt; ([TyCoVar] -&gt; [TyCoVar]) -&gt; [TyCoVar] -&gt; SDoc
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoVar] -&gt; [TyCoVar]
</span><a href="GHC.Core.TyCo.FVs.html#scopedSort"><span class="hs-identifier hs-var">scopedSort</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-969"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cannot be inferred from the right-hand side.&quot;</span></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-970"></span><span>               </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105109"><span class="hs-identifier hs-var">extra</span></a></span><span>
</span><span id="line-971"></span><span>
</span><span id="line-972"></span><span>      </span><span id="local-6989586621681105115"><span class="annot"><span class="annottext">what :: SDoc
</span><a href="#local-6989586621681105115"><span class="hs-identifier hs-var hs-var">what</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105123"><span class="hs-identifier hs-var">has_kinds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Type/kind&quot;</span></span><span>
</span><span id="line-973"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Type&quot;</span></span><span>
</span><span id="line-974"></span><span>
</span><span id="line-975"></span><span>      </span><span id="local-6989586621681105109"><span class="annot"><span class="annottext">extra :: SDoc
</span><a href="#local-6989586621681105109"><span class="hs-identifier hs-var hs-var">extra</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="#local-6989586621681105122"><span class="hs-identifier hs-var">undec_inst</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Using UndecidableInstances might help&quot;</span></span><span>
</span><span id="line-976"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">WhetherHasFamInst
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span>
</span><span id="line-977"></span><span>
</span><span id="line-978"></span><span class="hs-comment">-- | Report error message for equation that has a type family call at the top</span><span>
</span><span id="line-979"></span><span class="hs-comment">-- level of RHS</span><span>
</span><span id="line-980"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportTfHeadedErr"><span class="hs-identifier hs-type">reportTfHeadedErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-981"></span><span id="reportTfHeadedErr"><span class="annot"><span class="annottext">reportTfHeadedErr :: TyCon -&gt; CoAxBranch -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportTfHeadedErr"><span class="hs-identifier hs-var hs-var">reportTfHeadedErr</span></a></span></span><span> </span><span id="local-6989586621681105107"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105107"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span> </span><span id="local-6989586621681105106"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105106"><span class="hs-identifier hs-var">branch</span></a></span></span><span>
</span><span id="line-982"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(SrcSpan, SDoc)] -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#addErrs"><span class="hs-identifier hs-var">addErrs</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc -&gt; NonEmpty CoAxBranch -&gt; (SrcSpan, SDoc)
</span><a href="GHC.Tc.Instance.Family.html#buildInjectivityError"><span class="hs-identifier hs-var">buildInjectivityError</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105107"><span class="hs-identifier hs-var">fam_tc</span></a></span><span>
</span><span id="line-983"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Tc.Instance.Family.html#injectivityErrorHerald"><span class="hs-identifier hs-var">injectivityErrorHerald</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-984"></span><span>                 </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;RHS of injective type family equation cannot&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-985"></span><span>                 </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;be a type family:&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-986"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105106"><span class="hs-identifier hs-var">branch</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; [CoAxBranch] -&gt; NonEmpty CoAxBranch
forall a. a -&gt; [a] -&gt; NonEmpty a
</span><a href="../../base/src/GHC.Base.html#%3A%7C"><span class="hs-operator hs-var">:|</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-987"></span><span>
</span><span id="line-988"></span><span class="hs-comment">-- | Report error message for equation that has a bare type variable in the RHS</span><span>
</span><span id="line-989"></span><span class="hs-comment">-- but LHS pattern is not a bare type variable.</span><span>
</span><span id="line-990"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportBareVariableInRHSErr"><span class="hs-identifier hs-type">reportBareVariableInRHSErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-991"></span><span id="reportBareVariableInRHSErr"><span class="annot"><span class="annottext">reportBareVariableInRHSErr :: TyCon -&gt; [Type] -&gt; CoAxBranch -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportBareVariableInRHSErr"><span class="hs-identifier hs-var hs-var">reportBareVariableInRHSErr</span></a></span></span><span> </span><span id="local-6989586621681105105"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105105"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span> </span><span id="local-6989586621681105104"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105104"><span class="hs-identifier hs-var">tys</span></a></span></span><span> </span><span id="local-6989586621681105103"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105103"><span class="hs-identifier hs-var">branch</span></a></span></span><span>
</span><span id="line-992"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(SrcSpan, SDoc)] -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#addErrs"><span class="hs-identifier hs-var">addErrs</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc -&gt; NonEmpty CoAxBranch -&gt; (SrcSpan, SDoc)
</span><a href="GHC.Tc.Instance.Family.html#buildInjectivityError"><span class="hs-identifier hs-var">buildInjectivityError</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105105"><span class="hs-identifier hs-var">fam_tc</span></a></span><span>
</span><span id="line-993"></span><span>                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Tc.Instance.Family.html#injectivityErrorHerald"><span class="hs-identifier hs-var">injectivityErrorHerald</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-994"></span><span>                  </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;RHS of injective type family equation is a bare&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-995"></span><span>                  </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;type variable&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-996"></span><span>                  </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;but these LHS type and kind patterns are not bare&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-997"></span><span>                  </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;variables:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; SDoc
forall a. Outputable a =&gt; [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#pprQuotedList"><span class="hs-identifier hs-var">pprQuotedList</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621681105104"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-998"></span><span>                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105103"><span class="hs-identifier hs-var">branch</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; [CoAxBranch] -&gt; NonEmpty CoAxBranch
forall a. a -&gt; [a] -&gt; NonEmpty a
</span><a href="../../base/src/GHC.Base.html#%3A%7C"><span class="hs-operator hs-var">:|</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-999"></span><span>
</span><span id="line-1000"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#buildInjectivityError"><span class="hs-identifier hs-type">buildInjectivityError</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#NonEmpty"><span class="hs-identifier hs-type">NonEmpty</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#CoAxBranch"><span class="hs-identifier hs-type">CoAxBranch</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#SrcSpan"><span class="hs-identifier hs-type">SrcSpan</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1001"></span><span id="buildInjectivityError"><span class="annot"><span class="annottext">buildInjectivityError :: TyCon -&gt; SDoc -&gt; NonEmpty CoAxBranch -&gt; (SrcSpan, SDoc)
</span><a href="GHC.Tc.Instance.Family.html#buildInjectivityError"><span class="hs-identifier hs-var hs-var">buildInjectivityError</span></a></span></span><span> </span><span id="local-6989586621681105102"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105102"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span> </span><span id="local-6989586621681105101"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105101"><span class="hs-identifier hs-var">herald</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105100"><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105100"><span class="hs-identifier hs-var">eqn1</span></a></span></span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#%3A%7C"><span class="hs-operator hs-type">:|</span></a></span><span> </span><span id="local-6989586621681105099"><span class="annot"><span class="annottext">[CoAxBranch]
</span><a href="#local-6989586621681105099"><span class="hs-identifier hs-var">rest_eqns</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1002"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; SrcSpan
</span><a href="GHC.Core.Coercion.Axiom.html#coAxBranchSpan"><span class="hs-identifier hs-var">coAxBranchSpan</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105100"><span class="hs-identifier hs-var">eqn1</span></a></span><span>
</span><span id="line-1003"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Int -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681105101"><span class="hs-identifier hs-var">herald</span></a></span><span>
</span><span id="line-1004"></span><span>         </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoAxBranch -&gt; SDoc) -&gt; [CoAxBranch] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; CoAxBranch -&gt; SDoc
</span><a href="GHC.Core.Coercion.html#pprCoAxBranchUser"><span class="hs-identifier hs-var">pprCoAxBranchUser</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681105102"><span class="hs-identifier hs-var">fam_tc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxBranch
</span><a href="#local-6989586621681105100"><span class="hs-identifier hs-var">eqn1</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; [CoAxBranch] -&gt; [CoAxBranch]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[CoAxBranch]
</span><a href="#local-6989586621681105099"><span class="hs-identifier hs-var">rest_eqns</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1005"></span><span>
</span><span id="line-1006"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportConflictInstErr"><span class="hs-identifier hs-type">reportConflictInstErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstMatch"><span class="hs-identifier hs-type">FamInstMatch</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcRn"><span class="hs-identifier hs-type">TcRn</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1007"></span><span id="reportConflictInstErr"><span class="annot"><span class="annottext">reportConflictInstErr :: FamInst -&gt; [FamInstMatch] -&gt; TcM ()
</span><a href="GHC.Tc.Instance.Family.html#reportConflictInstErr"><span class="hs-identifier hs-var hs-var">reportConflictInstErr</span></a></span></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-1008"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- No conflicts</span><span>
</span><span id="line-1009"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#reportConflictInstErr"><span class="hs-identifier hs-var">reportConflictInstErr</span></a></span><span> </span><span id="local-6989586621681105095"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105095"><span class="hs-identifier hs-var">fam_inst</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681105094"><span class="annot"><span class="annottext">FamInstMatch
</span><a href="#local-6989586621681105094"><span class="hs-identifier hs-var">match1</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span class="annot"><span class="annottext">[FamInstMatch]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>
</span><span id="line-1010"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstMatch"><span class="hs-identifier hs-type">FamInstMatch</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fim_instance :: FamInstMatch -&gt; FamInst
</span><a href="GHC.Core.FamInstEnv.html#fim_instance"><span class="hs-identifier hs-var">fim_instance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681105093"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105093"><span class="hs-identifier hs-var">conf_inst</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FamInstMatch
</span><a href="#local-6989586621681105094"><span class="hs-identifier hs-var">match1</span></a></span><span>
</span><span id="line-1011"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105092"><span class="annot"><span class="annottext">sorted :: [FamInst]
</span><a href="#local-6989586621681105092"><span class="hs-identifier hs-var hs-var">sorted</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FamInst -&gt; FamInst -&gt; Ordering) -&gt; [FamInst] -&gt; [FamInst]
forall a. (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/Data.OldList.html#sortBy"><span class="hs-identifier hs-var">sortBy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SrcSpan -&gt; SrcSpan -&gt; Ordering
</span><a href="GHC.Types.SrcLoc.html#leftmost_smallest"><span class="hs-identifier hs-var">SrcLoc.leftmost_smallest</span></a></span><span> </span><span class="annot"><span class="annottext">(SrcSpan -&gt; SrcSpan -&gt; Ordering)
-&gt; (FamInst -&gt; SrcSpan) -&gt; FamInst -&gt; FamInst -&gt; Ordering
forall b c a. (b -&gt; b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; a -&gt; c
</span><a href="../../base/src/Data.Function.html#on"><span class="hs-operator hs-var">`on`</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; SrcSpan
</span><a href="#local-6989586621681105090"><span class="hs-identifier hs-var">getSpan</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105095"><span class="hs-identifier hs-var">fam_inst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105093"><span class="hs-identifier hs-var">conf_inst</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1012"></span><span>        </span><span id="local-6989586621681105089"><span class="annot"><span class="annottext">fi1 :: FamInst
</span><a href="#local-6989586621681105089"><span class="hs-identifier hs-var hs-var">fi1</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[FamInst] -&gt; FamInst
forall a. [a] -&gt; a
</span><a href="../../base/src/GHC.List.html#head"><span class="hs-identifier hs-var">head</span></a></span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105092"><span class="hs-identifier hs-var">sorted</span></a></span><span>
</span><span id="line-1013"></span><span>        </span><span id="local-6989586621681105087"><span class="annot"><span class="annottext">span :: SrcSpan
</span><a href="#local-6989586621681105087"><span class="hs-identifier hs-var hs-var">span</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxBranch -&gt; SrcSpan
</span><a href="GHC.Core.Coercion.Axiom.html#coAxBranchSpan"><span class="hs-identifier hs-var">coAxBranchSpan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; CoAxBranch
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomSingleBranch"><span class="hs-identifier hs-var">coAxiomSingleBranch</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInst -&gt; CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#famInstAxiom"><span class="hs-identifier hs-var">famInstAxiom</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105089"><span class="hs-identifier hs-var">fi1</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1014"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan -&gt; TcM () -&gt; TcM ()
forall a. SrcSpan -&gt; TcRn a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#setSrcSpan"><span class="hs-identifier hs-var">setSrcSpan</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681105087"><span class="hs-identifier hs-var">span</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM () -&gt; TcM ()) -&gt; TcM () -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; TcM ()
</span><a href="GHC.Tc.Utils.Monad.html#addErr"><span class="hs-identifier hs-var">addErr</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcM ()) -&gt; SDoc -&gt; TcM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1015"></span><span>    </span><span class="annot"><span class="annottext">SDoc -&gt; Int -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Conflicting family instance declarations:&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-1016"></span><span>       </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; CoAxBranch -&gt; SDoc
</span><a href="GHC.Core.Coercion.html#pprCoAxBranchUser"><span class="hs-identifier hs-var">pprCoAxBranchUser</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; TyCon
forall (br :: BranchFlag). CoAxiom br -&gt; TyCon
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomTyCon"><span class="hs-identifier hs-var">coAxiomTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105083"><span class="hs-identifier hs-var">ax</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; CoAxBranch
</span><a href="GHC.Core.Coercion.Axiom.html#coAxiomSingleBranch"><span class="hs-identifier hs-var">coAxiomSingleBranch</span></a></span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><a href="#local-6989586621681105083"><span class="hs-identifier hs-var">ax</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1017"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621681105082"><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105082"><span class="hs-identifier hs-var">fi</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[FamInst]
</span><a href="#local-6989586621681105092"><span class="hs-identifier hs-var">sorted</span></a></span><span>
</span><span id="line-1018"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681105083"><span class="annot"><span class="annottext">ax :: CoAxiom Unbranched
</span><a href="#local-6989586621681105083"><span class="hs-identifier hs-var hs-var">ax</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#famInstAxiom"><span class="hs-identifier hs-var">famInstAxiom</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681105082"><span class="hs-identifier hs-var">fi</span></a></span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1019"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-1020"></span><span>   </span><span id="local-6989586621681105090"><span class="annot"><span class="annottext">getSpan :: FamInst -&gt; SrcSpan
</span><a href="#local-6989586621681105090"><span class="hs-identifier hs-var hs-var">getSpan</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched -&gt; SrcSpan
forall a. NamedThing a =&gt; a -&gt; SrcSpan
</span><a href="GHC.Types.Name.html#getSrcSpan"><span class="hs-identifier hs-var">getSrcSpan</span></a></span><span> </span><span class="annot"><span class="annottext">(CoAxiom Unbranched -&gt; SrcSpan)
-&gt; (FamInst -&gt; CoAxiom Unbranched) -&gt; FamInst -&gt; SrcSpan
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; CoAxiom Unbranched
</span><a href="GHC.Core.FamInstEnv.html#famInstAxiom"><span class="hs-identifier hs-var">famInstAxiom</span></a></span><span>
</span><span id="line-1021"></span><span>   </span><span class="hs-comment">-- The sortBy just arranges that instances are displayed in order</span><span>
</span><span id="line-1022"></span><span>   </span><span class="hs-comment">-- of source location, which reduced wobbling in error messages,</span><span>
</span><span id="line-1023"></span><span>   </span><span class="hs-comment">-- and is better for users</span><span>
</span><span id="line-1024"></span><span>
</span><span id="line-1025"></span><span class="annot"><a href="GHC.Tc.Instance.Family.html#tcGetFamInstEnvs"><span class="hs-identifier hs-type">tcGetFamInstEnvs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span>
</span><span id="line-1026"></span><span class="hs-comment">-- Gets both the external-package inst-env</span><span>
</span><span id="line-1027"></span><span class="hs-comment">-- and the home-pkg inst env (includes module being compiled)</span><span>
</span><span id="line-1028"></span><span id="tcGetFamInstEnvs"><span class="annot"><span class="annottext">tcGetFamInstEnvs :: TcM (FamInstEnv, FamInstEnv)
</span><a href="GHC.Tc.Instance.Family.html#tcGetFamInstEnvs"><span class="hs-identifier hs-var hs-var">tcGetFamInstEnvs</span></a></span></span><span>
</span><span id="line-1029"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681105078"><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105078"><span class="hs-identifier hs-var">eps</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv ExternalPackageState
forall gbl lcl. TcRnIf gbl lcl ExternalPackageState
</span><a href="GHC.Tc.Utils.Monad.html#getEps"><span class="hs-identifier hs-var">getEps</span></a></span><span class="hs-special">;</span><span> </span><span id="local-6989586621681105077"><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105077"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
</span><a href="GHC.Tc.Utils.Monad.html#getGblEnv"><span class="hs-identifier hs-var">getGblEnv</span></a></span><span>
</span><span id="line-1030"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(FamInstEnv, FamInstEnv) -&gt; TcM (FamInstEnv, FamInstEnv)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ExternalPackageState -&gt; FamInstEnv
</span><a href="GHC.Driver.Types.html#eps_fam_inst_env"><span class="hs-identifier hs-var hs-var">eps_fam_inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">ExternalPackageState
</span><a href="#local-6989586621681105078"><span class="hs-identifier hs-var">eps</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcGblEnv -&gt; FamInstEnv
</span><a href="GHC.Tc.Types.html#tcg_fam_inst_env"><span class="hs-identifier hs-var hs-var">tcg_fam_inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681105077"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1031"></span></pre></body></html>